Skip to content

Commit

Permalink
Move autopilot initialization to prevent race (#5322)
Browse files Browse the repository at this point in the history
`establishLeadership` invoked during leadership monitoring may use autopilot to do promotions etc. There was a race with doing that and having autopilot initialized and this fixes it.
  • Loading branch information
mkeeler authored Feb 11, 2019
1 parent d7e4151 commit 7073ba4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ func NewServerLogger(config *Config, logger *log.Logger, tokens *token.Store) (*
s.Shutdown()
return nil, err
}


// Initialize Autopilot. This must happen before starting leadership monitoring
// as establishing leadership could attempt to use autopilot and cause a panic.
s.initAutopilot(config)

// Start monitoring leadership. This must happen after Serf is set up
// since it can fire events when leadership is obtained.
Expand All @@ -477,9 +482,6 @@ func NewServerLogger(config *Config, logger *log.Logger, tokens *token.Store) (*
// Start the metrics handlers.
go s.sessionStats()

// Initialize Autopilot
s.initAutopilot(config)

return s, nil
}

Expand Down

0 comments on commit 7073ba4

Please sign in to comment.