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.
This commit is contained in:
committed by
James Shubin
parent
fac004b774
commit
9ba9ef1cbf
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user