Browse Source

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

pull/7795/head
Sam Kleinman 2 years ago
committed by GitHub
parent
commit
c555226d2b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions
  1. +2
    -0
      internal/consensus/peer_state.go
  2. +2
    -0
      internal/consensus/reactor.go

+ 2
- 0
internal/consensus/peer_state.go 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"`


+ 2
- 0
internal/consensus/reactor.go 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()
}()
}
}


Loading…
Cancel
Save