Skip to content

Commit 805c16c

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 df0cbcc commit 805c16c

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
@@ -265,7 +265,9 @@ func (r *Reactor) Receive(e p2p.Envelope) {
265265
r.SendAddrs(e.Src, r.book.GetSelectionWithBias(biasToSelectNewPeers))
266266
go func() {
267267
// In a go-routine so it doesn't block .Receive.
268-
r.Switch.StopPeerGracefully(e.Src, r.String())
268+
if r.Switch != nil && r.Switch.IsRunning() {
269+
r.Switch.StopPeerGracefully(e.Src, r.String())
270+
}
269271
}()
270272

271273
} else {

0 commit comments

Comments
 (0)