From 56c0634918ace488555b445af1ea46fc748f98b0 Mon Sep 17 00:00:00 2001 From: Blake Mesdag Date: Mon, 15 Jan 2018 08:26:03 -0500 Subject: [PATCH] Return errors from Docker client.Events --- provider/docker/docker.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/provider/docker/docker.go b/provider/docker/docker.go index 3e2875c56..12f7f9127 100644 --- a/provider/docker/docker.go +++ b/provider/docker/docker.go @@ -2,6 +2,7 @@ package docker import ( "context" + "io" "math" "net" "net/http" @@ -237,16 +238,22 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s } eventsc, errc := dockerClient.Events(ctx, options) - for event := range eventsc { - if event.Action == "start" || - event.Action == "die" || - strings.HasPrefix(event.Action, "health_status") { - startStopHandle(event) + for { + select { + case event := <-eventsc: + if event.Action == "start" || + event.Action == "die" || + strings.HasPrefix(event.Action, "health_status") { + startStopHandle(event) + } + case err := <-errc: + if err == io.EOF { + log.Debug("Provider event stream closed") + } + + return err } } - if err := <-errc; err != nil { - return err - } } } return nil