Merge pull request #10465 from ziggie1984/bugfix/fix-peer-disconnect-log

peer: fix log output when not applicable
This commit is contained in:
Yong authored and GitHub committed 2026-02-11 11:41:20 +08:00
commit e53c4b1de5
1 file changed
+12 -2
+12 -2
View File
@@ -1648,15 +1648,25 @@ func (p *Brontide) Disconnect(reason error) {
// started, otherwise we will skip reading it as this chan won't be // started, otherwise we will skip reading it as this chan won't be
// closed, hence blocks forever. // closed, hence blocks forever.
if atomic.LoadInt32(&p.started) == 1 { if atomic.LoadInt32(&p.started) == 1 {
p.log.Debugf("Peer hasn't finished starting up yet, waiting " + // First check if startup has already completed (non-blocking).
"on startReady signal before closing connection") select {
case <-p.startReady:
// Startup already completed, no need to wait.
default:
// Still starting up, need to wait.
p.log.Debugf("Peer hasn't finished starting up yet, " +
"waiting on startReady signal before " +
"closing connection")
select { select {
case <-p.startReady: case <-p.startReady:
case <-p.cg.Done(): case <-p.cg.Done():
return return
} }
} }
}
err := fmt.Errorf("disconnecting %s, reason: %v", p, reason) err := fmt.Errorf("disconnecting %s, reason: %v", p, reason)
p.storeError(err) p.storeError(err)