Skip to content

Commit bd7d159

Browse files
committed
fix: more defensive approach to stopping peer in PEX
This helps with some flaky tests, and probably can eliminate some edge cases in real world.
1 parent 19cb61e commit bd7d159

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

p2p/pex/pex_reactor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ func (r *Reactor) Receive(e p2p.Envelope) {
268268
r.SendAddrs(e.Src, r.book.GetSelectionWithBias(biasToSelectNewPeers))
269269
go func() {
270270
// In a go-routine so it doesn't block .Receive.
271-
r.Switch.StopPeerGracefully(e.Src, r.String())
271+
if r.Switch != nil && r.Switch.IsRunning() {
272+
r.Switch.StopPeerGracefully(e.Src, r.String())
273+
}
272274
}()
273275

274276
} else {

0 commit comments

Comments
 (0)