Skip to content

Commit b07e921

Browse files
authored
Merge pull request docker#2785 from bn4t/2784-use-waitgroup-instead-of-sleep
Wait on waitgroup instead of using time.Sleep
2 parents a9c2c30 + 53e2110 commit b07e921

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cli/command/container/stats.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ func runStats(dockerCli command.Cli, opts *statsOptions) error {
156156
// Start a short-lived goroutine to retrieve the initial list of
157157
// containers.
158158
getContainerList()
159+
160+
// make sure each container get at least one valid stat data
161+
waitFirst.Wait()
159162
} else {
160163
// Artificially send creation events for the containers we were asked to
161164
// monitor (same code path than we use when monitoring all containers).
@@ -170,9 +173,9 @@ func runStats(dockerCli command.Cli, opts *statsOptions) error {
170173
// We don't expect any asynchronous errors: closeChan can be closed.
171174
close(closeChan)
172175

173-
// Do a quick pause to detect any error with the provided list of
174-
// container names.
175-
time.Sleep(1500 * time.Millisecond)
176+
// make sure each container get at least one valid stat data
177+
waitFirst.Wait()
178+
176179
var errs []string
177180
cStats.mu.Lock()
178181
for _, c := range cStats.cs {
@@ -186,8 +189,6 @@ func runStats(dockerCli command.Cli, opts *statsOptions) error {
186189
}
187190
}
188191

189-
// before print to screen, make sure each container get at least one valid stat data
190-
waitFirst.Wait()
191192
format := opts.format
192193
if len(format) == 0 {
193194
if len(dockerCli.ConfigFile().StatsFormat) > 0 {

0 commit comments

Comments
 (0)