Skip to content

Commit 5a8026a

Browse files
authored
Merge pull request #9249 from yyforyongyu/fix-shutdown
routing: fix missionControlStore blocks on shutting down
2 parents 4430687 + 4fe36f1 commit 5a8026a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

docs/release-notes/release-notes-0.19.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
back before the commitment tx was confirmed causing potentially force closes
4646
of the incoming channel.
4747

48+
* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/9249) found in the
49+
mission control store that can block the shutdown process of LND.
50+
4851
# New Features
4952
## Functional Enhancements
5053
## RPC Additions

routing/missioncontrol_store.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type missionControlStore struct {
5050
wg sync.WaitGroup
5151
db missionControlDB
5252

53+
// TODO(yy): Remove the usage of sync.Cond - we are better off using
54+
// channes than a Cond as suggested in the official godoc.
55+
//
5356
// queueCond is signalled when items are put into the queue.
5457
queueCond *sync.Cond
5558

@@ -347,15 +350,23 @@ func (b *missionControlStore) run() {
347350
// Wait for the queue to not be empty.
348351
b.queueCond.L.Lock()
349352
for b.queue.Front() == nil {
350-
b.queueCond.Wait()
351-
353+
// To make sure we can properly stop, we must
354+
// read the `done` channel first before
355+
// attempting to call `Wait()`. This is due to
356+
// the fact when `Signal` is called before the
357+
// `Wait` call, the `Wait` call will block
358+
// indefinitely.
359+
//
360+
// TODO(yy): replace this with channels.
352361
select {
353362
case <-b.done:
354363
b.queueCond.L.Unlock()
355364

356365
return
357366
default:
358367
}
368+
369+
b.queueCond.Wait()
359370
}
360371
b.queueCond.L.Unlock()
361372

0 commit comments

Comments
 (0)