From ed1eea9aea795ff8ce9282c78bf71161d84de58b Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 17 Mar 2023 12:15:22 +1300 Subject: [PATCH] basichost: prevent duplicate dials --- p2p/host/basic/basic_host.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index c11447974b..bee068fd9c 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -635,8 +635,13 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I } } - s, err := h.Network().NewStream(ctx, p) + s, err := h.Network().NewStream(network.WithNoDial(ctx, "already dialed"), p) if err != nil { + // TODO: It would be nicer to get the actual error from the swarm, + // but this will require some more work. + if errors.Is(err, network.ErrNoConn) { + return nil, errors.New("connection failed") + } return nil, err }