From 3e771a674cdcee508999e98e1cdcc30e1f7ed248 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 30 Jan 2017 08:49:07 -0800 Subject: [PATCH] terraform: acquire stopCh outside goroutine to ensure in lock --- terraform/context.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/terraform/context.go b/terraform/context.go index bd9e80aa0..85b7f582d 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -811,7 +811,8 @@ func (c *Context) walk( // Watch for a stop so we can call the provider Stop() API. doneCh := make(chan struct{}) - go c.watchStop(walker, doneCh) + stopCh := c.runContext.Done() + go c.watchStop(walker, doneCh, stopCh) // Walk the real graph, this will block until it completes realErr := graph.Walk(walker) @@ -906,12 +907,7 @@ func (c *Context) walk( return walker, realErr } -func (c *Context) watchStop(walker *ContextGraphWalker, doneCh <-chan struct{}) { - // Get the stop channel. runContext will never be nil since this should - // only be called within the context of an operation started with - // acquireRun - stopCh := c.runContext.Done() - +func (c *Context) watchStop(walker *ContextGraphWalker, doneCh, stopCh <-chan struct{}) { // Wait for a stop or completion select { case <-stopCh: