Browse Source

basichost: reset stream if SetProtocol fails (#2875)

pull/2879/head
sukun 4 months ago
committed by GitHub
parent
commit
76b266558b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      p2p/host/basic/basic_host.go

6
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
}

Loading…
Cancel
Save