consensus: tie peer threads to peer lifecylce context (#7792)

This commit is contained in:
Sam Kleinman
2022-02-09 12:01:12 -05:00
committed by GitHub
parent 860f78f000
commit c555226d2b
2 changed files with 4 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package consensus
import (
"context"
"encoding/json"
"errors"
"fmt"
@@ -40,6 +41,7 @@ type PeerState struct {
// NOTE: Modify below using setters, never directly.
mtx sync.RWMutex
cancel context.CancelFunc
running bool
PRS cstypes.PeerRoundState `json:"round_state"`
Stats *peerStateStats `json:"stats"`

View File

@@ -1009,6 +1009,7 @@ func (r *Reactor) processPeerUpdate(ctx context.Context, peerUpdate p2p.PeerUpda
// do not spawn multiple instances of the same goroutines and finally we
// set the waitgroup counter so we know when all goroutines have exited.
ps.SetRunning(true)
ctx, ps.cancel = context.WithCancel(ctx)
go func() {
select {
@@ -1045,6 +1046,7 @@ func (r *Reactor) processPeerUpdate(ctx context.Context, peerUpdate p2p.PeerUpda
r.mtx.Unlock()
ps.SetRunning(false)
ps.cancel()
}()
}
}