Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up messy defer logic in IDService.sendIdentifyResp #1169

Merged
merged 1 commit into from
Aug 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 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 @@ -412,7 +406,9 @@ func (ids *IDService) sendIdentifyResp(s network.Stream) {
}

ph.snapshotMu.RLock()
ids.writeChunkedIdentifyMsg(c, ph.snapshot, s)
snapshot := ph.snapshot
ph.snapshotMu.RUnlock()
Stebalien marked this conversation as resolved.
Show resolved Hide resolved
ids.writeChunkedIdentifyMsg(c, snapshot, s)
log.Debugf("%s sent message to %s %s", ID, c.RemotePeer(), c.RemoteMultiaddr())
}

Expand Down