Merge pull request #9249 from yyforyongyu/fix-shutdown

routing: fix missionControlStore blocks on shutting down
This commit is contained in:
Oliver Gugger
2024-11-08 11:09:45 +01:00
committed by GitHub
2 changed files with 16 additions and 2 deletions

View File

@@ -45,6 +45,9 @@
back before the commitment tx was confirmed causing potentially force closes back before the commitment tx was confirmed causing potentially force closes
of the incoming channel. of the incoming channel.
* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/9249) found in the
mission control store that can block the shutdown process of LND.
# New Features # New Features
## Functional Enhancements ## Functional Enhancements
## RPC Additions ## RPC Additions

View File

@@ -50,6 +50,9 @@ type missionControlStore struct {
wg sync.WaitGroup wg sync.WaitGroup
db missionControlDB db missionControlDB
// TODO(yy): Remove the usage of sync.Cond - we are better off using
// channes than a Cond as suggested in the official godoc.
//
// queueCond is signalled when items are put into the queue. // queueCond is signalled when items are put into the queue.
queueCond *sync.Cond queueCond *sync.Cond
@@ -347,8 +350,14 @@ func (b *missionControlStore) run() {
// Wait for the queue to not be empty. // Wait for the queue to not be empty.
b.queueCond.L.Lock() b.queueCond.L.Lock()
for b.queue.Front() == nil { for b.queue.Front() == nil {
b.queueCond.Wait() // To make sure we can properly stop, we must
// read the `done` channel first before
// attempting to call `Wait()`. This is due to
// the fact when `Signal` is called before the
// `Wait` call, the `Wait` call will block
// indefinitely.
//
// TODO(yy): replace this with channels.
select { select {
case <-b.done: case <-b.done:
b.queueCond.L.Unlock() b.queueCond.L.Unlock()
@@ -356,6 +365,8 @@ func (b *missionControlStore) run() {
return return
default: default:
} }
b.queueCond.Wait()
} }
b.queueCond.L.Unlock() b.queueCond.L.Unlock()