From 7cdd4bc984b98a730b674dd93112b0aedf15da9b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 13 Sep 2017 15:49:30 -0700 Subject: [PATCH] Reset on error in basic_host --- p2p/host/basic/basic_host.go | 8 ++++---- p2p/host/basic/basic_host_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 3f0f113..3a7874b 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -240,7 +240,7 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) { if h.negtimeout > 0 { if err := s.SetDeadline(time.Now().Add(h.negtimeout)); err != nil { log.Error("setting stream deadline: ", err) - s.Close() + s.Reset() return } } @@ -257,7 +257,7 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) { } else { log.Warning("protocol mux failed: %s (took %s)", err, took) } - s.Close() + s.Reset() return } @@ -269,7 +269,7 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) { if h.negtimeout > 0 { if err := s.SetDeadline(time.Time{}); err != nil { log.Error("resetting stream deadline: ", err) - s.Close() + s.Reset() return } } @@ -364,7 +364,7 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I selected, err := msmux.SelectOneOf(protoStrs, s) if err != nil { - s.Close() + s.Reset() return nil, err } selpid := protocol.ID(selected) diff --git a/p2p/host/basic/basic_host_test.go b/p2p/host/basic/basic_host_test.go index af4a830..4c14934 100644 --- a/p2p/host/basic/basic_host_test.go +++ b/p2p/host/basic/basic_host_test.go @@ -180,7 +180,7 @@ func TestHostProtoMismatch(t *testing.T) { h1.SetStreamHandler("/super", func(s inet.Stream) { t.Error("shouldnt get here") - s.Close() + s.Reset() }) _, err := h2.NewStream(ctx, h1.ID(), "/foo", "/bar", "/baz/1.0.0") -- GitLab