Skip to content

Commit

Permalink
Check channel closed state in /events loop
Browse files Browse the repository at this point in the history
When listener channel is closed, it becomes always available for
reading: select becomes an active loop which writes default-constructed
events (i.e: empty strings).

Fixes docker#5766.

Docker-DCO-1.1-Signed-off-by: Arnaud Porterie <arnaud.porterie@gmail.com> (github: icecrime)
  • Loading branch information
icecrime committed May 14, 2014
1 parent 4af465f commit 8699f53
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Anthony Bishopric <git@anthonybishopric.com>
Anton Nikitin <anton.k.nikitin@gmail.com>
Antony Messerli <amesserl@rackspace.com>
apocas <petermdias@gmail.com>
Arnaud Porterie <arnaud.porterie@gmail.com>
Asbjørn Enge <asbjorn@hanafjedle.net>
Barry Allard <barry.allard@gmail.com>
Bartłomiej Piotrowski <b@bpiotrowski.pl>
Expand Down
5 changes: 4 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ func (srv *Server) Events(job *engine.Job) engine.Status {
}
for {
select {
case event := <-listener:
case event, ok := <-listener:
if !ok { // Channel is closed: listener was evicted
return engine.StatusOK
}
err := sendEvent(&event)
if err != nil && err.Error() == "JSON error" {
continue
Expand Down

0 comments on commit 8699f53

Please sign in to comment.