Skip to content

Commit

Permalink
peer: select on p.quit during stall control chan writes
Browse files Browse the repository at this point in the history
Hangs at peer disconnect were observed due to the blocking writes on the
buffered stall control channel.  This is a new bug that was introduced after
the recent queuing changes that allow more messages to be read at a time.
  • Loading branch information
jrick committed Nov 7, 2023
1 parent c1e4cdd commit 4d3d345
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 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,10 @@ out:
p.statsMtx.Unlock()
}

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

0 comments on commit 4d3d345

Please sign in to comment.