Fix segfault due to race condition for checking server versions (#7957)

The ACL monitoring routine uses c.routers to check for server version updates. Therefore it needs to be started after initializing the routers.
This commit is contained in:
Matt Keeler 2020-06-03 10:36:32 -04:00 committed by GitHub
parent 99eb583ebc
commit 0e4c65d422
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -181,10 +181,6 @@ func NewClientLogger(config *Config, logger hclog.InterceptLogger, tlsConfigurat
return nil, fmt.Errorf("Failed to start lan serf: %v", err) return nil, fmt.Errorf("Failed to start lan serf: %v", err)
} }
if c.acls.ACLsEnabled() {
go c.monitorACLMode()
}
// Start maintenance task for servers // Start maintenance task for servers
c.routers = router.New(c.logger, c.shutdownCh, c.serf, c.connPool, "") c.routers = router.New(c.logger, c.shutdownCh, c.serf, c.connPool, "")
go c.routers.Start() go c.routers.Start()
@ -193,6 +189,12 @@ func NewClientLogger(config *Config, logger hclog.InterceptLogger, tlsConfigurat
// handlers depend on the router and the router depends on Serf. // handlers depend on the router and the router depends on Serf.
go c.lanEventHandler() go c.lanEventHandler()
// This needs to happen after initializing c.routers to prevent a race
// condition where the router manager is used when the pointer is nil
if c.acls.ACLsEnabled() {
go c.monitorACLMode()
}
if err := c.startEnterprise(); err != nil { if err := c.startEnterprise(); err != nil {
c.Shutdown() c.Shutdown()
return nil, err return nil, err

View File

@ -235,6 +235,10 @@ func (m *Manager) FindServer() *metadata.Server {
} }
func (m *Manager) checkServers(fn func(srv *metadata.Server) bool) bool { func (m *Manager) checkServers(fn func(srv *metadata.Server) bool) bool {
if m == nil {
return true
}
for _, srv := range m.getServerList().servers { for _, srv := range m.getServerList().servers {
if !fn(srv) { if !fn(srv) {
return false return false