From 9ba9ef1cbf1addecf912ad7cc085a7f6a663e6a9 Mon Sep 17 00:00:00 2001 From: Jonathan Gold Date: Wed, 22 Nov 2017 15:46:59 -0500 Subject: [PATCH] resources: aws: ec2: Close closeChan before server shutdown This patch makes sure that closeChan is closed as soon as the main loop returns, so any channel operations are unblocked before we run shutdown. This ensures that the server's goroutine can return before shutdown completes and we don't panic by trying to serve the client after shutdown returns. --- resources/aws_ec2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/aws_ec2.go b/resources/aws_ec2.go index f9693ccb..3c9a7c58 100644 --- a/resources/aws_ec2.go +++ b/resources/aws_ec2.go @@ -632,7 +632,6 @@ func (obj *AwsEc2Res) snsWatch() error { send := false var exit *error defer obj.wg.Wait() - defer close(obj.closeChan) // create the sns listener // closing is handled by http.Server.Shutdown in the defer func below listener, err := obj.snsListener(obj.WatchListenAddr) @@ -655,6 +654,7 @@ func (obj *AwsEc2Res) snsWatch() error { log.Printf("%s: sns server shutdown cancelled", obj) } }() + defer close(obj.closeChan) obj.wg.Add(1) // start the sns server go func() {