peer+lnd: fix peer blocking on node shutdown

This commit fixes a case where the peer blocks the shutdown process.
During the shutdown, the server will call `s.DisconnectPeer`, which
calls `peer.Disconnect`. Because the peer never enters `peer.Start` via
`s.peerInitializer`, the `startReady` chan will not be closed, causing
`peer.Disconnect` to hang forever. We now fix it by only block on
`startReady` when the peer is started.
This commit is contained in:
yyforyongyu
2024-11-16 10:54:22 +08:00
parent 95b248a1ef
commit fe03aa0201
2 changed files with 34 additions and 10 deletions

View File

@@ -1467,10 +1467,18 @@ func (p *Brontide) Disconnect(reason error) {
// Make sure initialization has completed before we try to tear things
// down.
select {
case <-p.startReady:
case <-p.quit:
return
//
// NOTE: We only read the `startReady` chan if the peer has been
// started, otherwise we will skip reading it as this chan won't be
// closed, hence blocks forever.
if atomic.LoadInt32(&p.started) == 1 {
p.log.Debugf("Started, waiting on startReady signal")
select {
case <-p.startReady:
case <-p.quit:
return
}
}
err := fmt.Errorf("disconnecting %s, reason: %v", p, reason)