From 559595ba1f3f0d5b87f691940c165b2a7618abb6 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Tue, 19 Jul 2016 20:27:50 -0700 Subject: [PATCH] agent: call remove after operation is finished To avoid calling Controller methods concurrently, `Controller.Remove` is now called only *after* the last operation has proceeded. We do this by checking to see if the cancellation is available to detect an outstanding operation needs to be completed. Once the operation returns, we proceed with the shutdown procedure. Signed-off-by: Stephen J Day --- agent/task.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/agent/task.go b/agent/task.go index 797f93c769..e769a4835a 100644 --- a/agent/task.go +++ b/agent/task.go @@ -93,7 +93,7 @@ func (tm *taskManager) run(ctx context.Context) { case <-run: // always check for shutdown before running. select { - case <-shutdown: + case <-tm.shutdown: continue // ignore run request and handle shutdown case <-tm.closed: continue @@ -142,6 +142,13 @@ func (tm *taskManager) run(ctx context.Context) { // goal is to decide whether or not we re-dispatch the operation. cancel = nil + select { + case <-tm.shutdown: + shutdown = tm.shutdown // re-enable the shutdown branch + continue // no dispatch if we are in shutdown. + default: + } + switch err { case exec.ErrTaskNoop: if !updated { @@ -203,6 +210,12 @@ func (tm *taskManager) run(ctx context.Context) { if cancel != nil { // cancel outstanding operation. cancel() + + // subtle: after a cancellation, we want to avoid busy wait + // here. this gets renabled in the errs branch and we'll come + // back around and try shutdown again. + shutdown = nil // turn off this branch until op proceeds + continue // wait until operation actually exits. } // TODO(stevvooe): This should be left for the repear.