Skip to content

Commit

Permalink
basichost: reset stream if SetProtocol fails (#2875)
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt authored and MarcoPolo committed Jul 18, 2024
1 parent a7e3a28 commit 724e1fa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,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
}

Expand Down

0 comments on commit 724e1fa

Please sign in to comment.