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

Release the monitor-set lock before sync event callbacks

Public commit record

What the developer wrote

Authored by auto-pr-bot

91/100 · Strong
Release the monitor-set lock before sync event callbacks

@matt asked in #5589:

> @auto-pr-bot please fix this issue reported by project loupe
>
> ## Description
>
> The synchronous EventsProvider implementation holds
> self.monitors.read() throughout each
> ChannelMonitor::process_pending_events call, including the application
> callback. Both its documentation and EventsProvider explicitly permit
> callbacks to re-enter the provider. A callback that flushes a queued
> new monitor acquires flush_lock and pending_ops, then
> watch_channel_internal waits for self.monitors.write(). The same
> thread still owns the outer read guard and cannot release it until the
> callback returns, so production deadlocks. The blocked flush also
> retains the global operation-queue lock, preventing subsequent
> deferred monitor updates.
>
> [...]
>
> Exploitation is integration-dependent: an application must use
> synchronous event handling and perform a checkpoint/flush from its
> event callback (or another operation requiring the monitor-set write
> lock). A channel counterparty can trigger that callback through an
> on-chain close producing SpendableOutputs, while another registration
> is queued. This stalls event processing and monitor-update flushing;
> if processing remains stalled, time-sensitive claim handling can be
> affected.

`process_pending_events_async` already re-acquires the monitors read
lock around each monitor's event processing instead of holding it
across the handler; this applies the same structure to the synchronous
`EventsProvider` implementation, using the shared `process_events_body!`
macro. A regression test queues a monitor registration and flushes it
from the event handler, which the test lock checker detects as a
deadlock on the previous code.

Fixes #5589

Requested-by: @matt
Link: https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/issues/5589
Authored-By: matt/GLM-5.3-Flash-GGUF:Q4_K_XL <goose@users.noreply.local>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a deadlock bug in the rust-lightning library's ChainMonitor. When an application handled certain blockchain events synchronously, the library held a read lock while calling the application's handler. If that handler tried to flush a newly queued channel monitor, it needed a write lock on the same data structure, which the same thread still held as a read lock. This caused a self-deadlock, stalling event processing and time-sensitive on-chain claim handling. The fix releases the read lock before invoking the application callback and re-acquires it afterward, mirroring how the asynchronous event path already worked. A regression test confirms the previously deadlocking scenario now succeeds.

Recommended action

Upgrade to a release containing this commit. If running synchronous event handling with deferred monitor persistence, ensure this patch is applied, as the deadlock can stall both event processing and monitor flushes, potentially affecting time-sensitive on-chain claims. Review any custom event handlers that re-enter ChainMonitor to confirm they no longer trigger the deadlock on older versions.

Security signals we found

01

Deadlock between read and write locks on the same thread

02

Re-entrant callback holding a lock the callback itself may need to upgrade

03

Stalled event processing can delay time-sensitive on-chain claim transactions

04

Global operation-queue lock retained during the stall, blocking deferred monitor updates

05

Fix aligns synchronous path with already-safe asynchronous path

Risk score

Why this scored 64/100

Our methodology →
Potential impact 22/30
Exploitability 12/25
Stealth signal 8/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.