From aca173412988ed983eaad691899e761405446f46 Mon Sep 17 00:00:00 2001 From: Hussam Date: Wed, 1 May 2024 11:14:15 -0500 Subject: [PATCH] Correctly cleanup/sever stream when forced to by remote peer --- p2p/node/streamManager/streamManager.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/p2p/node/streamManager/streamManager.go b/p2p/node/streamManager/streamManager.go index f4b5b36a52..ee7cdc3245 100644 --- a/p2p/node/streamManager/streamManager.go +++ b/p2p/node/streamManager/streamManager.go @@ -81,8 +81,13 @@ func NewStreamManager(peerCount int, node quaiprotocol.QuaiP2PNode, host host.Ho }, nil } +// Expects a key as peerID and value of *streamWrapper func severStream(key interface{}, value interface{}) { - stream := value.(network.Stream) + wrappedStream, ok := value.(*streamWrapper) + if !ok { + return + } + stream := wrappedStream.stream err := stream.Close() if err != nil { log.Global.WithField("err", err).Error("Failed to close stream") @@ -98,10 +103,9 @@ func (sm *basicStreamManager) CloseStream(peerID p2p.PeerID) error { wrappedStream, ok := sm.streamCache.Get(peerID) if ok { - stream := wrappedStream.(*streamWrapper).stream - log.Global.WithField("peerID", peerID).Debug("Pruned connection with peer") - severStream(peerID, stream) + severStream(peerID, wrappedStream) sm.streamCache.Remove(peerID) + log.Global.WithField("peerID", peerID).Debug("Pruned connection with peer") return nil } return errStreamNotFound