Move autopilot initialization to prevent race (#5322)

`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.
This commit is contained in:
Matt Keeler 2019-02-11 11:12:24 -05:00 committed by GitHub
parent e67f1722f6
commit fa2c7059a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -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.
@ -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
}