From bf63d2e844f5c49e9c1047411fb42f8895e6a892 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sat, 12 Jan 2019 17:56:45 -0500 Subject: [PATCH] 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. --- engine/graph/state.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/engine/graph/state.go b/engine/graph/state.go index e86f2d55..e3fdc05d 100644 --- a/engine/graph/state.go +++ b/engine/graph/state.go @@ -246,6 +246,16 @@ func (obj *State) Poke() { obj.wg.Add(1) 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 { case obj.outputChan <- nil: