engine: graph: Avoid a possible panic sending on a closed channel

It's plausible that we send on a closed channel if we're running a back
poke and it tries to send a poke on something that has already closed.
If it detects this condition, it will exit.

Unfortunately, it's not clear if the wait group will protect this case,
but hopefully this will hold us until we can re-write the needed parts
of the engine.
This commit is contained in:
James Shubin
2019-01-12 17:56:45 -05:00
parent b808592fb3
commit bf63d2e844

View File

@@ -246,6 +246,16 @@ func (obj *State) Poke() {
obj.wg.Add(1) obj.wg.Add(1)
defer obj.wg.Done() defer obj.wg.Done()
// now that we've added to the wait group, obj.outputChan won't close...
// so see if there's an exit signal before we release the wait group!
// XXX: i don't think this is necessarily happening, but maybe it is?
// XXX: re-write some of the engine to ensure that: "the sender closes"!
select {
case <-obj.exit.Signal():
return // skip sending the poke b/c we're closing
default:
}
select { select {
case obj.outputChan <- nil: case obj.outputChan <- nil: