Skip to content

Commit 8d7a09f

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 b0938ef commit 8d7a09f

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
@@ -4074,6 +4074,10 @@ impl PersistenceNotifier {
40744074
loop {
40754075
let &(ref mtx, ref cvar) = &self.persistence_lock;
40764076
let mut guard = mtx.lock().unwrap();
4077+
if *guard {
4078+
*guard = false;
4079+
return;
4080+
}
40774081
guard = cvar.wait(guard).unwrap();
40784082
let result = *guard;
40794083
if result {
@@ -4089,6 +4093,10 @@ impl PersistenceNotifier {
40894093
loop {
40904094
let &(ref mtx, ref cvar) = &self.persistence_lock;
40914095
let mut guard = mtx.lock().unwrap();
4096+
if *guard {
4097+
*guard = false;
4098+
return true;
4099+
}
40924100
guard = cvar.wait_timeout(guard, max_wait).unwrap().0;
40934101
// Due to spurious wakeups that can happen on `wait_timeout`, here we need to check if the
40944102
// desired wait time has actually passed, and if not then restart the loop with a reduced wait

0 commit comments

Comments
 (0)