diff --git a/api/client/container/stats.go b/api/client/container/stats.go index 46861514cd..b2a45a984c 100644 --- a/api/client/container/stats.go +++ b/api/client/container/stats.go @@ -192,13 +192,23 @@ func runStats(dockerCli *client.DockerCli, opts *statsOptions) error { for range time.Tick(500 * time.Millisecond) { printHeader() + toRemove := []string{} cStats.mu.Lock() for _, s := range cStats.cs { if err := s.Display(w); err != nil && !opts.noStream { logrus.Debugf("stats: got error for %s: %v", s.Name, err) + if err == io.EOF { + toRemove = append(toRemove, s.Name) + } } } cStats.mu.Unlock() + for _, name := range toRemove { + cStats.remove(name) + } + if len(cStats.cs) == 0 && !showAll { + return nil + } w.Flush() if opts.noStream { break diff --git a/api/client/container/stats_helpers.go b/api/client/container/stats_helpers.go index 6083669644..336ad14760 100644 --- a/api/client/container/stats_helpers.go +++ b/api/client/container/stats_helpers.go @@ -97,6 +97,10 @@ func (s *containerStats) Collect(ctx context.Context, cli client.APIClient, stre if err := dec.Decode(&v); err != nil { dec = json.NewDecoder(io.MultiReader(dec.Buffered(), responseBody)) u <- err + if err == io.EOF { + break + } + time.Sleep(100 * time.Millisecond) continue }