Skip to content

Commit

Permalink
basichost: don't wait for Identify in Host.NewStream
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Sep 5, 2023
1 parent b058e65 commit b2d7d03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
12 changes: 0 additions & 12 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,18 +647,6 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
return nil, fmt.Errorf("failed to open stream: %w", err)
}

// Wait for any in-progress identifies on the connection to finish. This
// is faster than negotiating.
//
// If the other side doesn't support identify, that's fine. This will
// just be a no-op.
select {
case <-h.ids.IdentifyWait(s.Conn()):
case <-ctx.Done():
_ = s.Reset()
return nil, fmt.Errorf("identify failed to complete: %w", ctx.Err())
}

pref, err := h.preferredProtocol(p, pids)
if err != nil {
_ = s.Reset()
Expand Down
9 changes: 9 additions & 0 deletions p2p/host/basic/basic_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,17 @@ func TestProtoDowngrade(t *testing.T) {
// This is _almost_ instantaneous, but this test fails once every ~1k runs without this.
time.Sleep(time.Millisecond)

sub, err := h1.EventBus().Subscribe(&event.EvtPeerIdentificationCompleted{})
require.NoError(t, err)
defer sub.Close()

h2pi := h2.Peerstore().PeerInfo(h2.ID())
require.NoError(t, h1.Connect(ctx, h2pi))
select {
case <-sub.Out():
case <-time.After(5 * time.Second):
t.Fatal("timeout")
}

s2, err := h1.NewStream(ctx, h2.ID(), "/testing/1.0.0", "/testing")
require.NoError(t, err)
Expand Down

0 comments on commit b2d7d03

Please sign in to comment.