app: fix hang when application is closed

Events are Send() after the pump is being stopped (src is not read any more).
This blocks a critical go routine, resulting in the application not properly being stopped.

By continue reading the src channel during shutting down the pump, the block is removed and the application is able to stop.

Fixes golang/go#20256

Change-Id: I1536e8697cd4a0e504e7359e48acce04088e5760
Reviewed-on: https://go-review.googlesource.com/42811
Reviewed-by: Elias Naur <elias.naur@gmail.com>
diff --git a/app/app.go b/app/app.go
index fdcb4d0..e228b13 100644
--- a/app/app.go
+++ b/app/app.go
@@ -150,13 +150,14 @@
 		const initialSize = 16
 		i, j, buf, mask := 0, 0, make([]interface{}, initialSize), initialSize-1
 
-		maybeSrc := src
+		srcActive := true
 		for {
 			maybeDst := dst
 			if i == j {
 				maybeDst = nil
 			}
-			if maybeDst == nil && maybeSrc == nil {
+			if maybeDst == nil && !srcActive {
+				// Pump is stopped and empty.
 				break
 			}
 
@@ -165,9 +166,13 @@
 				buf[i&mask] = nil
 				i++
 
-			case e := <-maybeSrc:
+			case e := <-src:
 				if _, ok := e.(stopPumping); ok {
-					maybeSrc = nil
+					srcActive = false
+					continue
+				}
+
+				if !srcActive {
 					continue
 				}