From 2e52f9d1e48641bef09a38396e8ba2612d7e8517 Mon Sep 17 00:00:00 2001 From: Cam Date: Mon, 22 Feb 2021 15:54:54 -0800 Subject: [PATCH] container stats: ignore context.Canceled errors we often receive context.Canceled errors when a container exits during docker stats collection. there is a benign race condition where if we process the error first before processing that the context is "Done", then we will log this canceled error as a warning message here: https://github.com/aws/amazon-ecs-agent/blob/5be7aa08bed215a557f48c16d8201ad3db59a9be/agent/stats/container.go#L118-L122 this change ignores these context.Canceled errors so that we don't log them. This will eliminate log messages that look like this when a container exits: level=warn time=2020-12-25T07:51:33Z msg="Error encountered processing metrics stream from docker, this may affect cloudwatch metric accuracy: DockerGoClient: Unable to decode stats for container REDACTED: context canceled" module=container.go --- agent/stats/container.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/agent/stats/container.go b/agent/stats/container.go index 2880791431d..9e2a412e7a0 100644 --- a/agent/stats/container.go +++ b/agent/stats/container.go @@ -118,8 +118,13 @@ func (container *StatsContainer) processStatsStream() error { case <-container.ctx.Done(): return nil case err := <-errC: - seelog.Warnf("Error encountered processing metrics stream from docker, this may affect cloudwatch metric accuracy: %s", err) - returnError = true + select { + case <-container.ctx.Done(): + // ignore error when container.ctx.Done() + default: + seelog.Warnf("Error encountered processing metrics stream from docker, this may affect cloudwatch metric accuracy: %s", err) + returnError = true + } case rawStat, ok := <-dockerStats: if !ok { if returnError {