AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 60 Bitcoin

Reset `persistence_in_flight` counter on error in LSPS1/LSPS2

Public commit record

What the developer wrote

Authored by Elias Rohrer

73/100 · Adequate
Reset `persistence_in_flight` counter on error in LSPS1/LSPS2

Previously, if any `.await?` in the persist loop returned an error, the
`?` would propagate out of `persist()` before reaching the `fetch_sub`
at the end of the loop. This left the counter permanently > 0, causing
all subsequent `persist()` calls to early-return and effectively
disabling persistence for the lifetime of the handler.

Fix this by extracting the loop into `do_persist()` and unconditionally
resetting the counter via `store(0, Release)` in the outer `persist()`
after `do_persist()` returns, regardless of success or failure.

Co-Authored-By: HAL 9000
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit fixes a bug in two Lightning liquidity service modules (LSPS1 and LSPS2). Previously, if saving data to disk failed partway through, an internal 'persistence in flight' counter would stay stuck above zero. Once stuck, the code would skip all future disk-saving attempts for the lifetime of the running service. This could silently stop important state from being saved, potentially leading to data loss or inconsistent service state after a restart. The fix wraps the save loop in a helper function and always resets the counter to zero afterward, whether the save succeeded or failed.

Recommended action

Review whether any other atomic counters or locks in the codebase rely on `fetch_sub` at the end of an async loop with `?` early returns, and apply the same wrapper/cleanup pattern. Consider adding a regression test that injects an I/O error during `persist()` and verifies subsequent persistence calls still execute.

Security signals we found

01

Denial-of-service-like liveness failure: persistence disabled for the lifetime of the handler after any I/O error

02

State inconsistency risk: unsaved state could lead to stale or lost LSPS1/LSPS2 service data

03

Atomic counter leak via early return on `?` error path

04

Fix pattern: unconditional resource cleanup in wrapper function

Risk score

Why this scored 60/100

Our methodology →
Potential impact 18/30
Exploitability 8/25
Stealth signal 12/15
Affected reach 10/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.