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 Jul 18, 2024
1 parent d84736f commit 76b2665
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 @@ -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
}

Expand Down

0 comments on commit 76b2665

Please sign in to comment.