mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-26 21:51:27 +02:00
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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user