From f32cc97fb1601a4d826bc1a0694ea6b708768a01 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Fri, 16 Dec 2016 17:25:51 -0800 Subject: [PATCH] if protocol selection fails, reset remembered protocols --- p2p/host/basic/basic_host.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index b2bf0e341f..2ec11fb64b 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -2,6 +2,7 @@ package basichost import ( "context" + "fmt" "io" "time" @@ -219,7 +220,17 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I } if pref != "" { - return h.newStream(ctx, p, pref) + s, err := h.newStream(ctx, p, pref) + if err != msmux.ErrNotSupported { + return s, err + } + + log.Warning("protocol preference selection failed: %s [%s] %s", p, pids, pref) + + // protocol selection failed, clear ALL remembered protocols for them + if err := h.Peerstore().SetProtocols(p); err != nil { + return nil, fmt.Errorf("clearing peerstore protocols: %s", err) + } } var protoStrs []string