diff --git a/masterelection/masterelection.go b/masterelection/masterelection.go index 231be050d39be71495b70644485324aca1853a91..da2f9fd4a2f4c3a6442fe91194bd084e9ef348d3 100644 --- a/masterelection/masterelection.go +++ b/masterelection/masterelection.go @@ -63,16 +63,15 @@ func (m *MasterElection) GetMasterAddr() string { } func (m *MasterElection) setState(state int) { - if m.State == state { - return - } log.Printf("masterelection: %s -> %s", stateToString(m.State), stateToString(state)) + // Order is important here: set state before triggering the + // update channel so that the receiver sees the right value. + m.State = state if m.StateChange != nil { m.StateChange <- state } - m.State = state } func (m *MasterElection) stopper() {