Skip to content

Commit

Permalink
clean up messy defer logic in IDService.sendIdentifyResp
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Aug 24, 2021
1 parent 0741d17 commit fd8f2ba
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -399,6 +392,7 @@ func (ids *IDService) sendIdentifyResp(s network.Stream) {
return
}

var ph *peerHandler
select {
case ph = <-phCh:
case <-ids.ctx.Done():
Expand All @@ -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())
}

Expand Down

0 comments on commit fd8f2ba

Please sign in to comment.