Skip to content

Commit

Permalink
Fix segfault due to race condition for checking server versions (#7957)
Browse files Browse the repository at this point in the history
The ACL monitoring routine uses c.routers to check for server version updates. Therefore it needs to be started after initializing the routers.
  • Loading branch information
mkeeler authored and hashicorp-ci committed Jun 3, 2020
1 parent 08297cb commit 3b8769b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions agent/consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ func NewClientLogger(config *Config, logger hclog.InterceptLogger, tlsConfigurat
return nil, fmt.Errorf("Failed to start lan serf: %v", err)
}

if c.acls.ACLsEnabled() {
go c.monitorACLMode()
}

// Start maintenance task for servers
c.routers = router.New(c.logger, c.shutdownCh, c.serf, c.connPool, "")
go c.routers.Start()
Expand All @@ -191,6 +187,12 @@ func NewClientLogger(config *Config, logger hclog.InterceptLogger, tlsConfigurat
// handlers depend on the router and the router depends on Serf.
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 {
c.Shutdown()
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions agent/router/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func (m *Manager) FindServer() *metadata.Server {
}

func (m *Manager) checkServers(fn func(srv *metadata.Server) bool) bool {
if m == nil {
return true
}

for _, srv := range m.getServerList().servers {
if !fn(srv) {
return false
Expand Down

0 comments on commit 3b8769b

Please sign in to comment.