From 232864175dea83b375770cf275fb29f4e3b7d641 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 5 Nov 2016 15:26:07 -0700 Subject: [PATCH] make sure to always close streams when youre done with them --- p2p/host/basic/basic_host.go | 1 + p2p/protocol/identify/id.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 355f549..d0c1575 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -117,6 +117,7 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) { } else { log.Warning("protocol mux failed: %s (took %s)", err, took) } + s.Close() return } s.SetProtocol(protocol.ID(protoID)) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index 36e08b2..baffc5a 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -87,6 +87,7 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { c.Close() return } + defer s.Close() s.SetProtocol(ID) @@ -97,7 +98,6 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { if err := msmux.SelectProtoOrFail(ID, s); err != nil { log.Debugf("error writing stream header for %s", ID) log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer()) - s.Close() return } -- GitLab