Skip to content

Commit 7920f35

Browse files
committed
Add reenatrancy guard for process_pending_htlc_forwards
We add a reenatrancy guard to disallow entering `process_pending_htlc_forwards` multiple times. This makes sure that we'd skip any additional processing calls if a prior round/batch of processing is still underway.
1 parent c85edf2 commit 7920f35

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6337,6 +6337,11 @@ where
63376337
///
63386338
/// Will regularly be called by the background processor.
63396339
pub fn process_pending_htlc_forwards(&self) {
6340+
static REENTRANCY_GUARD: AtomicBool = AtomicBool::new(false);
6341+
if REENTRANCY_GUARD.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed).is_err() {
6342+
return;
6343+
}
6344+
63406345
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
63416346
let mut should_persist = NotifyOption::SkipPersistNoEvents;
63426347
self.process_pending_update_add_htlcs();
@@ -7178,6 +7183,7 @@ where
71787183
}
71797184
should_persist
71807185
});
7186+
REENTRANCY_GUARD.store(false, Ordering::Release);
71817187
}
71827188

71837189
/// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors.

0 commit comments

Comments
 (0)