Skip to content

Commit ecc15f3

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 69b9799 commit ecc15f3

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
@@ -4078,6 +4078,10 @@ impl PersistenceNotifier {
40784078
loop {
40794079
let &(ref mtx, ref cvar) = &self.persistence_lock;
40804080
let mut guard = mtx.lock().unwrap();
4081+
if *guard {
4082+
*guard = false;
4083+
return;
4084+
}
40814085
guard = cvar.wait(guard).unwrap();
40824086
let result = *guard;
40834087
if result {
@@ -4093,6 +4097,10 @@ impl PersistenceNotifier {
40934097
loop {
40944098
let &(ref mtx, ref cvar) = &self.persistence_lock;
40954099
let mut guard = mtx.lock().unwrap();
4100+
if *guard {
4101+
*guard = false;
4102+
return true;
4103+
}
40964104
guard = cvar.wait_timeout(guard, max_wait).unwrap().0;
40974105
// Due to spurious wakeups that can happen on `wait_timeout`, here we need to check if the
40984106
// desired wait time has actually passed, and if not then restart the loop with a reduced wait

0 commit comments

Comments
 (0)