From c247cd8fea64b00690a7f20d5f9c93b8c8a4c1b2 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 5 Feb 2017 18:45:28 -0500 Subject: [PATCH] resources: Don't double close on Running restart If we use the "retry" metaparam on a Watch, we want to avoid a double close due to the second Running() signal. This avoids this with a simple flag. --- resources/resources.go | 1 + resources/sendrecv.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/resources/resources.go b/resources/resources.go index aab7f910..58794306 100644 --- a/resources/resources.go +++ b/resources/resources.go @@ -197,6 +197,7 @@ type BaseRes struct { state ResState working bool // is the Worker() loop running ? started chan struct{} // closed when worker is started/running + isStarted bool // did the started chan already close? starter bool // does this have indegree == 0 ? XXX: usually? isStateOK bool // whether the state is okay based on events or not isGrouped bool // am i contained within a group? diff --git a/resources/sendrecv.go b/resources/sendrecv.go index 0ed0dcb4..86bb77b8 100644 --- a/resources/sendrecv.go +++ b/resources/sendrecv.go @@ -108,8 +108,11 @@ func (obj *BaseRes) Running(processChan chan *event.Event) error { cuid.SetConverged(true) // a reasonable initial assumption } - obj.StateOK(false) // assume we're initially dirty - close(obj.started) // send started signal + obj.StateOK(false) // assume we're initially dirty + if !obj.isStarted { // this avoids a double close when/if watch retries + obj.isStarted = true + close(obj.started) // send started signal + } var err error if obj.starter { // vertices of indegree == 0 should send initial pokes