Skip to content

Commit

Permalink
app: fix hang when application is closed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
veger committed Aug 28, 2018
1 parent 0f31740 commit fd30dfe
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/app.go
Expand Up @@ -150,13 +150,14 @@ func pump(dst chan interface{}) (src chan interface{}) {
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
}

Expand All @@ -165,9 +166,13 @@ func pump(dst chan interface{}) (src chan interface{}) {
buf[i&mask] = nil
i++

case e := <-maybeSrc:
case e := <-src:
if _, ok := e.(stopPumping); ok {
maybeSrc = nil
srcActive = false
continue
}

if !srcActive {
continue
}

Expand Down

0 comments on commit fd30dfe

Please sign in to comment.