From aedd1555d343f394781d9b74514dda5bccbe40f4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 4 Sep 2013 22:21:59 -0700 Subject: [PATCH] builder/digitalocean: properly cleanup goroutines for status checking --- builder/digitalocean/wait.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builder/digitalocean/wait.go b/builder/digitalocean/wait.go index 388e27978..ba2b03cb0 100644 --- a/builder/digitalocean/wait.go +++ b/builder/digitalocean/wait.go @@ -9,6 +9,9 @@ import ( // waitForState simply blocks until the droplet is in // a state we expect, while eventually timing out. func waitForDropletState(desiredState string, dropletId uint, client *DigitalOceanClient, timeout time.Duration) error { + done := make(chan struct{}) + defer close(done) + result := make(chan error, 1) go func() { attempts := 0 @@ -29,6 +32,15 @@ func waitForDropletState(desiredState string, dropletId uint, client *DigitalOce // Wait 3 seconds in between time.Sleep(3 * time.Second) + + // Verify we shouldn't exit + select { + case <-done: + // We finished, so just exit the goroutine + return + default: + // Keep going + } } }()