Make the defer statement of waitgroup to execute last
This commit is contained in:
parent
ea2e677f02
commit
5ed10f4074
|
@ -437,6 +437,7 @@ func (c *ServerCommand) Run(args []string) int {
|
|||
}
|
||||
}
|
||||
|
||||
// Wait for dependant goroutines to complete
|
||||
c.WaitGroup.Wait()
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -421,6 +421,7 @@ func (c *ConsulBackend) RunServiceDiscovery(shutdownTriggered *bool, waitGroup *
|
|||
return err
|
||||
}
|
||||
|
||||
// 'server' command will wait for the belog goroutine to complete
|
||||
waitGroup.Add(1)
|
||||
|
||||
go c.runEventDemuxer(shutdownTriggered, waitGroup, shutdownCh, advertiseAddr, activeFunc, sealedFunc)
|
||||
|
@ -429,6 +430,9 @@ func (c *ConsulBackend) RunServiceDiscovery(shutdownTriggered *bool, waitGroup *
|
|||
}
|
||||
|
||||
func (c *ConsulBackend) runEventDemuxer(shutdownTriggered *bool, waitGroup *sync.WaitGroup, shutdownCh ShutdownChannel, advertiseAddr string, activeFunc activeFunction, sealedFunc sealedFunction) {
|
||||
// This defer statement should be executed last. So push it first.
|
||||
defer waitGroup.Done()
|
||||
|
||||
// Fire the reconcileTimer immediately upon starting the event demuxer
|
||||
reconcileTimer := time.NewTimer(0)
|
||||
defer reconcileTimer.Stop()
|
||||
|
@ -519,7 +523,6 @@ shutdown:
|
|||
if err := c.client.Agent().ServiceDeregister(registeredServiceID); err != nil {
|
||||
c.logger.Printf("[WARN]: physical/consul: service deregistration failed: %v", err)
|
||||
}
|
||||
defer waitGroup.Done()
|
||||
}
|
||||
|
||||
// checkID returns the ID used for a Consul Check. Assume at least a read
|
||||
|
|
Loading…
Reference in a new issue