From 4ced3644423fed5822413dcefe4f04fc2f26dd4c Mon Sep 17 00:00:00 2001 From: tycho garen Date: Wed, 9 Mar 2022 09:09:24 -0500 Subject: [PATCH] minimal --- internal/consensus/invalid_test.go | 6 ++++-- internal/consensus/reactor.go | 11 ++++++++--- internal/consensus/state.go | 9 +++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/internal/consensus/invalid_test.go b/internal/consensus/invalid_test.go index 0b4fdf830..85e92da79 100644 --- a/internal/consensus/invalid_test.go +++ b/internal/consensus/invalid_test.go @@ -91,9 +91,11 @@ func TestReactorInvalidPrecommit(t *testing.T) { t.Fatal("test condition did not fire") } case <-ctx.Done(): - if _, ok := <-signal; !ok { + select { + case <-signal: + // pass + default: t.Fatal("test condition did not fire after timeout") - return } case <-signal: // test passed diff --git a/internal/consensus/reactor.go b/internal/consensus/reactor.go index c8d296ff9..1774e8052 100644 --- a/internal/consensus/reactor.go +++ b/internal/consensus/reactor.go @@ -865,10 +865,15 @@ func (r *Reactor) queryMaj23Routine(ctx context.Context, ps *PeerState) { return } - rs := r.getRoundState() - prs := ps.GetRoundState() // TODO create more reliable coppies of these // structures so the following go routines don't race + rs := r.state.GetRoundState() + prs := ps.GetRoundState() + select { + case <-ctx.Done(): + return + default: + } wg := &sync.WaitGroup{} @@ -1027,7 +1032,7 @@ func (r *Reactor) processPeerUpdate(ctx context.Context, peerUpdate p2p.PeerUpda // Send our state to the peer. If we're block-syncing, broadcast a // RoundStepMessage later upon SwitchToConsensus(). if !r.WaitSync() { - go func() { _ = r.sendNewRoundStepMessage(ctx, ps.peerID) }() + _ = r.sendNewRoundStepMessage(ctx, ps.peerID) } }() diff --git a/internal/consensus/state.go b/internal/consensus/state.go index 55718cd31..287705943 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -286,9 +286,9 @@ func (cs *State) GetRoundState() *cstypes.RoundState { cs.mtx.RLock() defer cs.mtx.RUnlock() - // NOTE: this might be dodgy, as RoundState itself isn't thread - // safe as it contains a number of pointers and is explicitly - // not thread safe. + // NOTE: this is probably be dodgy, as RoundState isn't thread + // safe as it contains a number of pointers which make the + // resulting object shared anyway rs := cs.RoundState // copy return &rs } @@ -351,8 +351,9 @@ func (cs *State) SetPrivValidator(ctx context.Context, priv types.PrivValidator) // testing. func (cs *State) SetTimeoutTicker(timeoutTicker TimeoutTicker) { cs.mtx.Lock() + defer cs.mtx.Unlock() cs.timeoutTicker = timeoutTicker - cs.mtx.Unlock() + } // LoadCommit loads the commit for a given height.