From e436bcc3917fca066bc328221e679a388fdb9738 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 10 Sep 2018 15:51:09 -0700 Subject: [PATCH] always remove connection from identify service map fixes #419 Also call FullClose in a goroutine; no need to block this. (not happy with that but I'm starting to think we need to rethink stream closing, again...) --- p2p/protocol/identify/id.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index fb94985..1f8dc01 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -83,7 +83,12 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { ids.currid[c] = ch ids.currmu.Unlock() - defer close(ch) + defer func() { + close(ch) + ids.currmu.Lock() + delete(ids.currid, c) + ids.currmu.Unlock() + }() s, err := c.NewStream() if err != nil { @@ -103,16 +108,6 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { } ids.responseHandler(s) - - ids.currmu.Lock() - _, found := ids.currid[c] - delete(ids.currid, c) - ids.currmu.Unlock() - - if !found { - log.Errorf("IdentifyConn failed to find channel (programmer error) for %s", c) - } - inet.FullClose(s) } func (ids *IDService) requestHandler(s inet.Stream) { @@ -135,12 +130,14 @@ func (ids *IDService) responseHandler(s inet.Stream) { mes := pb.Identify{} if err := r.ReadMsg(&mes); err != nil { log.Warning("error reading identify message: ", err) + s.Reset() return } ids.consumeMessage(&mes, c) - log.Debugf("%s received message from %s %s", ID, c.RemotePeer(), c.RemoteMultiaddr()) + + go inet.FullClose(s) } func (ids *IDService) populateMessage(mes *pb.Identify, c inet.Conn) { -- GitLab