Skip to content

Commit e2561ac

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 4a8edf6 commit e2561ac

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
@@ -4081,6 +4081,10 @@ impl PersistenceNotifier {
40814081
loop {
40824082
let &(ref mtx, ref cvar) = &self.persistence_lock;
40834083
let mut guard = mtx.lock().unwrap();
4084+
if *guard {
4085+
*guard = false;
4086+
return;
4087+
}
40844088
guard = cvar.wait(guard).unwrap();
40854089
let result = *guard;
40864090
if result {
@@ -4096,6 +4100,10 @@ impl PersistenceNotifier {
40964100
loop {
40974101
let &(ref mtx, ref cvar) = &self.persistence_lock;
40984102
let mut guard = mtx.lock().unwrap();
4103+
if *guard {
4104+
*guard = false;
4105+
return true;
4106+
}
40994107
guard = cvar.wait_timeout(guard, max_wait).unwrap().0;
41004108
// Due to spurious wakeups that can happen on `wait_timeout`, here we need to check if the
41014109
// desired wait time has actually passed, and if not then restart the loop with a reduced wait

0 commit comments

Comments
 (0)