hashicorp / raft-autopilot

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

Zero out the state when restarted instead of nilling the pointer #10

Closed mkeeler closed 3 years ago

mkeeler commented 3 years ago

During New we initialize to a non-nil state so during shutdown we should put it back in that state instead of nil.

The buildServerState function relies on it not being nil. We could have added a nil check there but since we already initialize to non nil it seemed better to reinitialize instead of account for the nil elsewhere.

For background context this is non-nil so that things can use the GetState function to retrieve a pointer to the current state with us never overwriting the state that we have already given out to callers. We could have the state be a non-pointer member but then GetState would need to perform a copy. I still think I prefer the pointer approach.

The changes to the life cycle test are to exercise an actual restart which is where the panic was triggered before. Without the fix the test panics, with the fix its all fine.