Start server rebalance task after init'ing Serf

Now that there is no longer an event loop driven directly by Serf, start the ServerManager task after Serf has been setup.  When testing and adjusting timers and timeouts to unreasonably low values, it's possible to tickle a race condition where Serf's NumNodes() would fail because Serf had not been initialized.
This commit is contained in:
Sean Chittenden 2016-03-26 21:59:45 -07:00
parent ee95c55d88
commit 92c2e8e668
1 changed files with 6 additions and 6 deletions

View File

@ -119,12 +119,7 @@ func NewClient(config *Config) (*Client, error) {
shutdownCh: make(chan struct{}),
}
c.serverMgr = server_manager.New(c.logger, c.shutdownCh, c.serf, c.connPool)
// Start maintenance task for serverMgr
go c.serverMgr.Start()
// Start the Serf listeners to prevent a deadlock
// Start lan event handlers before lan Serf setup to prevent deadlock
go c.lanEventHandler()
// Initialize the lan Serf
@ -134,6 +129,11 @@ func NewClient(config *Config) (*Client, error) {
c.Shutdown()
return nil, fmt.Errorf("Failed to start lan serf: %v", err)
}
// Start maintenance task for server_manager
c.serverMgr = server_manager.New(c.logger, c.shutdownCh, c.serf, c.connPool)
go c.serverMgr.Start()
return c, nil
}