From d17ee4b506af842b2d9fe6f8736b4636e32db599 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 18 Apr 2016 11:12:07 -0700 Subject: [PATCH] Create a copy of stats value before modifications Fixes #22030 Because the publisher uses this same value to all the stats endpoints we need to make a copy of this as soon as we get it so that we can make our modifications without it affecting others. Signed-off-by: Michael Crosby --- daemon/stats.go | 4 ++-- daemon/stats_collector_unix.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/daemon/stats.go b/daemon/stats.go index 33a9e723a1..7ebae41dc7 100644 --- a/daemon/stats.go +++ b/daemon/stats.go @@ -43,11 +43,11 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c var preCPUStats types.CPUStats getStatJSON := func(v interface{}) *types.StatsJSON { - ss := v.(*types.StatsJSON) + ss := v.(types.StatsJSON) ss.PreCPUStats = preCPUStats // ss.MemoryStats.Limit = uint64(update.MemoryLimit) preCPUStats = ss.CPUStats - return ss + return &ss } enc := json.NewEncoder(outStream) diff --git a/daemon/stats_collector_unix.go b/daemon/stats_collector_unix.go index fb1931dfb8..1f016322df 100644 --- a/daemon/stats_collector_unix.go +++ b/daemon/stats_collector_unix.go @@ -135,7 +135,7 @@ func (s *statsCollector) run() { // FIXME: move to containerd stats.CPUStats.SystemUsage = systemUsage - pair.publisher.Publish(stats) + pair.publisher.Publish(*stats) } } }