Browse code

Check channel closed state in /events loop

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 #5766.

Docker-DCO-1.1-Signed-off-by: Arnaud Porterie <arnaud.porterie@gmail.com> (github: icecrime)

Arnaud Porterie authored on 2014/05/15 05:24:11
Showing 2 changed files
... ...
@@ -28,6 +28,7 @@ Anthony Bishopric <git@anthonybishopric.com>
28 28
 Anton Nikitin <anton.k.nikitin@gmail.com>
29 29
 Antony Messerli <amesserl@rackspace.com>
30 30
 apocas <petermdias@gmail.com>
31
+Arnaud Porterie <arnaud.porterie@gmail.com>
31 32
 Asbjørn Enge <asbjorn@hanafjedle.net>
32 33
 Barry Allard <barry.allard@gmail.com>
33 34
 Bartłomiej Piotrowski <b@bpiotrowski.pl>
... ...
@@ -259,7 +259,10 @@ func (srv *Server) Events(job *engine.Job) engine.Status {
259 259
 	}
260 260
 	for {
261 261
 		select {
262
-		case event := <-listener:
262
+		case event, ok := <-listener:
263
+			if !ok { // Channel is closed: listener was evicted
264
+				return engine.StatusOK
265
+			}
263 266
 			err := sendEvent(&event)
264 267
 			if err != nil && err.Error() == "JSON error" {
265 268
 				continue