Skip to content

Commit c6a1893

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 f070fef commit c6a1893

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
@@ -4084,6 +4084,10 @@ impl PersistenceNotifier {
40844084
loop {
40854085
let &(ref mtx, ref cvar) = &self.persistence_lock;
40864086
let mut guard = mtx.lock().unwrap();
4087+
if *guard {
4088+
*guard = false;
4089+
return;
4090+
}
40874091
guard = cvar.wait(guard).unwrap();
40884092
let result = *guard;
40894093
if result {
@@ -4099,6 +4103,10 @@ impl PersistenceNotifier {
40994103
loop {
41004104
let &(ref mtx, ref cvar) = &self.persistence_lock;
41014105
let mut guard = mtx.lock().unwrap();
4106+
if *guard {
4107+
*guard = false;
4108+
return true;
4109+
}
41024110
guard = cvar.wait_timeout(guard, max_wait).unwrap().0;
41034111
// Due to spurious wakeups that can happen on `wait_timeout`, here we need to check if the
41044112
// desired wait time has actually passed, and if not then restart the loop with a reduced wait

0 commit comments

Comments
 (0)