diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index c950289d85..e2e3ad36b1 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -381,14 +381,7 @@ func (ids *IDService) identifyConn(c network.Conn, signal chan struct{}) { } func (ids *IDService) sendIdentifyResp(s network.Stream) { - var ph *peerHandler - - defer func() { - _ = s.Close() - if ph != nil { - ph.snapshotMu.RUnlock() - } - }() + defer s.Close() c := s.Conn() @@ -399,6 +392,7 @@ func (ids *IDService) sendIdentifyResp(s network.Stream) { return } + var ph *peerHandler select { case ph = <-phCh: case <-ids.ctx.Done(): @@ -413,6 +407,7 @@ func (ids *IDService) sendIdentifyResp(s network.Stream) { ph.snapshotMu.RLock() ids.writeChunkedIdentifyMsg(c, ph.snapshot, s) + ph.snapshotMu.RUnlock() log.Debugf("%s sent message to %s %s", ID, c.RemotePeer(), c.RemoteMultiaddr()) }