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

Merge bitcoin/bitcoin#36011: btcsignals: destroy callbacks on disconnect

Public commit record

What the developer wrote

Authored by merge-script

100/100 · Strong
Merge bitcoin/bitcoin#36011: btcsignals: destroy callbacks on disconnect

a318b23131e6df2c64e8fe79cebc8e5babdf8b7f btcsignals: fall back to atomic_load/store without __cpp_lib_atomic_shared_ptr (Ryan Ofsky)
f1d786c1ef5d813f61e405370a67df4cc6323885 btcsignals: destroy callbacks eagerly on disconnect (Ryan Ofsky)
7c5571adc46857cfcf77d81b6fc135dee5369749 test: characterize btcsignals callback destruction timing (Ryan Ofsky)

Pull request description:

Currently callback functions connected to signals do not get freed when their `connection::disconnect` method is called or when their associated `scoped_connection` is destroyed. They live as long as the signal does, even if they will never be called, and can only get [garbage collected](https://github.com/bitcoin/bitcoin/blob/0fd515bbb7070a502dd2fe6d16f5f3cbac591283/src/util/btcsignals.h#L240-L241) if new connections are added.

This behavior is different that previous boost signals behavior and causes a [deadlock](https://github.com/bitcoin/bitcoin/actions/runs/31848571315/job/94919834743) on GUI shutdown in #10102 because when the node registers signal callbacks (`handleInitMessage`, etc) that get forwarded to the GUI, the callbacks own `mp::EventLoopRef` references, and if the callbacks aren't freed, the node process can't shut down.

This change restores boost signals behavior freeing callbacks when they are disconnected or when `scoped_connection` objects are destroyed to avoid this problem and make callback lifetimes more predictable.

ACKs for top commit:
hodlinator:
re-ACK a318b23131e6df2c64e8fe79cebc8e5babdf8b7f
sedited:
Re-ACK a318b23131e6df2c64e8fe79cebc8e5babdf8b7f

Tree-SHA512: 41be63f7adbb1d1556698624a1aaaf62b4c574a29c3f3a8f35505b3c70fda472b6c8d6009a7f13eabe5670657197d7c471720cbf0eb9474d76cf9e2b5852ce44
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This change fixes a bug in Bitcoin Core's internal signal/callback system where callback functions and the resources they own were not released when disconnected. Previously, disconnected callbacks lingered until the signal itself was destroyed or new connections triggered garbage collection. This caused a real-world deadlock during GUI shutdown because node-to-GUI callbacks held references that prevented the node process from exiting. The patch makes callbacks get destroyed immediately on disconnect (or after any in-flight call finishes), matching the behavior of the older Boost signals library.

Recommended action

Apply the patch. It is a defensive correctness fix that prevents resource leaks and shutdown deadlocks. No immediate incident response is required beyond normal merge/verification, but downstream users running GUI builds should update to include this fix.

Security signals we found

01

Resource lifetime bug in custom signal/slot implementation

02

Deadlock on GUI shutdown due to unreleased callback-owned references

03

Behavioral divergence from boost::signals2 callback lifetime semantics

04

Thread-safe callback destruction with concurrent invocation handling

Risk score

Why this scored 29/100

Our methodology →
Potential impact 8/30
Exploitability 2/25
Stealth signal 3/15
Affected reach 5/15
Confidence 7/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.