Skip to content

Commit c95a365

Browse files
committed
Do not wait in PersistenceNotifier when the persist flag is set
When we had a event which caused us to set the persist flag in a PersistenceNotifier in between wait calls, we will still wait, potentially not persisting a ChannelManager when we should. Worse, for wait_timeout, this caused us to always wait up to the timeout, but then always return true that a persistence is needed. Instead, we simply check the persist flag before waiting, returning immediately if it is set.
1 parent e2328d6 commit c95a365

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,6 +4088,10 @@ impl PersistenceNotifier {
40884088
loop {
40894089
let &(ref mtx, ref cvar) = &self.persistence_lock;
40904090
let mut guard = mtx.lock().unwrap();
4091+
if *guard {
4092+
*guard = false;
4093+
return;
4094+
}
40914095
guard = cvar.wait(guard).unwrap();
40924096
let result = *guard;
40934097
if result {
@@ -4103,6 +4107,10 @@ impl PersistenceNotifier {
41034107
loop {
41044108
let &(ref mtx, ref cvar) = &self.persistence_lock;
41054109
let mut guard = mtx.lock().unwrap();
4110+
if *guard {
4111+
*guard = false;
4112+
return true;
4113+
}
41064114
guard = cvar.wait_timeout(guard, max_wait).unwrap().0;
41074115
// Due to spurious wakeups that can happen on `wait_timeout`, here we need to check if the
41084116
// desired wait time has actually passed, and if not then restart the loop with a reduced wait

0 commit comments

Comments
 (0)