From dd788c563190da5b7d068ad51fa49f3d37072ccc Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 11 Jul 2016 20:54:32 -0400 Subject: [PATCH] consensus: fix race from OnStop accessing cs.Height --- consensus/state.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/consensus/state.go b/consensus/state.go index 338568b30..d76c82969 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -321,7 +321,10 @@ func (cs *ConsensusState) startRoutines(maxSteps int) { } func (cs *ConsensusState) OnStop() { + cs.mtx.Lock() // NOTE: OnStop prints the cs.Height, which might be concurrently updated ... cs.QuitService.OnStop() + cs.mtx.Unlock() + if cs.wal != nil && cs.IsRunning() { cs.wal.Wait() }