Browse code

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 <crosbymichael@gmail.com>

Michael Crosby authored on 2016/04/19 03:12:07
Showing 2 changed files
... ...
@@ -43,11 +43,11 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c
43 43
 
44 44
 	var preCPUStats types.CPUStats
45 45
 	getStatJSON := func(v interface{}) *types.StatsJSON {
46
-		ss := v.(*types.StatsJSON)
46
+		ss := v.(types.StatsJSON)
47 47
 		ss.PreCPUStats = preCPUStats
48 48
 		// ss.MemoryStats.Limit = uint64(update.MemoryLimit)
49 49
 		preCPUStats = ss.CPUStats
50
-		return ss
50
+		return &ss
51 51
 	}
52 52
 
53 53
 	enc := json.NewEncoder(outStream)
... ...
@@ -135,7 +135,7 @@ func (s *statsCollector) run() {
135 135
 			// FIXME: move to containerd
136 136
 			stats.CPUStats.SystemUsage = systemUsage
137 137
 
138
-			pair.publisher.Publish(stats)
138
+			pair.publisher.Publish(*stats)
139 139
 		}
140 140
 	}
141 141
 }