From f98de20f7e196650654c11ce8201e83fe225edfb Mon Sep 17 00:00:00 2001 From: "M. J. Fromberger" Date: Mon, 11 Jul 2022 16:34:05 -0700 Subject: [PATCH] p2p: ensure closed channels stop receiving service (#8979) Once these channels are closed, we should not continue to service them, as they will never again deliver nonzero values. --- internal/p2p/router.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/p2p/router.go b/internal/p2p/router.go index 56558a80f..55377169c 100644 --- a/internal/p2p/router.go +++ b/internal/p2p/router.go @@ -427,8 +427,10 @@ func (r *Router) routeChannel( ) { for { select { - case envelope := <-outCh: - if envelope.IsZero() { + case envelope, ok := <-outCh: + if !ok { + return + } else if envelope.IsZero() { continue } // Mark the envelope with the channel ID to allow sendPeer() to pass @@ -507,7 +509,10 @@ func (r *Router) routeChannel( } } - case peerError := <-errCh: + case peerError, ok := <-errCh: + if !ok { + return + } maxPeerCapacity := r.peerManager.HasMaxPeerCapacity() r.logger.Error("peer error", "peer", peerError.NodeID,