From 6dc5e19c544de677f81070a0e3f030c5dc5a8a4e Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 14 May 2016 23:43:45 -0700 Subject: [PATCH] close wait channel in all cases, not just success --- p2p/protocol/identify/id.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index ce8ea91c..e756bb06 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -72,9 +72,12 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { <-wait // already identifying it. wait for it. return } - ids.currid[c] = make(chan struct{}) + ch := make(chan struct{}) + ids.currid[c] = ch ids.currmu.Unlock() + defer close(ch) + s, err := c.NewStream() if err != nil { log.Debugf("error opening initial stream for %s: %s", ID, err) @@ -97,7 +100,7 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { ids.ResponseHandler(s) ids.currmu.Lock() - ch, found := ids.currid[c] + _, found := ids.currid[c] delete(ids.currid, c) ids.currmu.Unlock() @@ -105,8 +108,6 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { log.Debugf("IdentifyConn failed to find channel (programmer error) for %s", c) return } - - close(ch) // release everyone waiting. } func (ids *IDService) RequestHandler(s inet.Stream) {