hashicorp / raft-autopilot

Raft Autopilot
Mozilla Public License 2.0
21 stars 5 forks source link

Make restarting Autopilot make more sense #6

Closed mkeeler closed 3 years ago

mkeeler commented 3 years ago

Fixes #5

Previously a Stop/Start could result in autopilot not running if the go routines running the background hadn’t finished stopping by the time Start was called.

There are a few changes in here to fix that.

First the running status is now tracked by a constant which can have 1 of 3 states instead of a boolean. This is to be able to represent a shutting down state.

When in the shutting down state, if Start is called it will replace the current execution info with a new one. The newly spawned go routine will however acquire and hold onto the execMutex for its lifetime. If it is cancelled prior to gaining that lock (this shouldn’t happen) then it should immediately exit.

The addition of the execMutex allows for multiple autopilot go routines to co-exist without the possibility of them stomping on each others toes.