From 76b266558bb77d71106788f68931ce1ad0adf38a Mon Sep 17 00:00:00 2001 From: sukun Date: Thu, 18 Jul 2024 17:38:25 +0530 Subject: [PATCH] basichost: reset stream if SetProtocol fails (#2875) --- p2p/host/basic/basic_host.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index e6be5c5c2f..a5eba01d72 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -732,8 +732,10 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I return nil, fmt.Errorf("failed to negotiate protocol: %w", ctx.Err()) } - s.SetProtocol(selected) - h.Peerstore().AddProtocols(p, selected) + if err := s.SetProtocol(selected); err != nil { + return nil, err + } + _ = h.Peerstore().AddProtocols(p, selected) // adding the protocol to the peerstore isn't critical return s, nil }