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

peer: select on p.quit during stall control chan writes #3209

Merged
merged 1 commit into from
Nov 7, 2023
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
24 changes: 20 additions & 4 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,10 +1256,18 @@ out:
break out
}
atomic.StoreInt64(&p.lastRecv, time.Now().Unix())
p.stallControl <- stallControlMsg{sccReceiveMessage, rmsg}
select {
case p.stallControl <- stallControlMsg{sccReceiveMessage, rmsg}:
case <-p.quit:
break out
}

// Handle each supported message type.
p.stallControl <- stallControlMsg{sccHandlerStart, rmsg}
select {
case p.stallControl <- stallControlMsg{sccHandlerStart, rmsg}:
case <-p.quit:
break out
}
switch msg := rmsg.(type) {
case *wire.MsgVersion:
// Limit to one version message per peer.
Expand Down Expand Up @@ -1432,7 +1440,11 @@ out:
log.Debugf("Received unhandled message of type %v "+
"from %v", rmsg.Command(), p)
}
p.stallControl <- stallControlMsg{sccHandlerDone, rmsg}
select {
case p.stallControl <- stallControlMsg{sccHandlerDone, rmsg}:
case <-p.quit:
break out
}
}

// Ensure connection is closed.
Expand Down Expand Up @@ -1609,7 +1621,11 @@ out:
p.statsMtx.Unlock()
}

p.stallControl <- stallControlMsg{sccSendMessage, msg.msg}
select {
case p.stallControl <- stallControlMsg{sccSendMessage, msg.msg}:
case <-p.quit:
break out
}
if err := p.writeMessage(msg.msg); err != nil {
p.Disconnect()
if p.shouldLogWriteError(err) {
Expand Down