Review report

core: PR #36011

2 minor findings · 1 suggestion

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · Liveness queries can destroy callbacks under the signal mutex

A connected() query racing with disconnect() can become the callback's last owner and run capture destructors under the signal mutex, potentially deadlocking reentrant destruction.

Location: src/util/btcsignals.h:113 (head).

Details and suggested fix

connected() obtains an owning shared_ptr through load(). If another thread clears m_callback after that load, disconnect() can return before the query releases the final reference and destroys the callback. The predicates in connect() and empty() perform this release while holding the nonrecursive m_mutex. A capture destructor that re-enters the same signal through either method, or waits for work needing that mutex, can therefore deadlock. Although base connect() could already destroy callbacks during garbage collection, this change newly makes liveness queries destruction points and contradicts the documented disconnect-or-invocation destruction timing. Restore a separate atomic liveness flag, clear it before clearing m_callback, and use it for queries and garbage collection; reserve owning callback loads for emission. The race window is narrow, and no current caller whose callback destructor re-enters its signal or waits on its mutex was identified, so production impact remains unconfirmed.


Link

[minor] · The middle commit lacks the libc++ atomic shared-pointer fallback

Commit f1d786c1 fails to build on libraries without atomic shared-pointer support because its fallback arrives only in a318b231, preventing builds and bisects at the intermediate revision.

Location: src/util/btcsignals.h:59 (head).

Details and suggested fix

Commit f1d786c1 declares std::atomic<std::shared_ptr<const void>> m_callback unconditionally. On libc++ versions without the C++20 specialization, the generic atomic<T> rejects the non-trivially-copyable shared_ptr. The wrapper introduced in a318b231 fixes the final head but not that intermediate commit. Its commit message identifies failures on Xcode 16.2, FreeBSD 15.1 and the custom-libc++ MSan/TSan builds; Xcode CLT 16.2 is also the documented supported minimum. This conflicts with CONTRIBUTING.md's requirement that each commit build independently and obstructs bisecting on affected toolchains. Squash a318b231 into f1d786c1 so the behavior change includes its portability fallback.


Optional improvements

Link

[suggestion] · The signal-destruction guarantee omits surviving connection handles

A still-connected plain connection can keep its callback alive after signal destruction, contrary to the new header guarantee and test comment.

Location: src/util/btcsignals.h:30 (head).

Details and suggested fix

connect() returns a plain connection sharing ownership of the connection_holder through m_state, and that holder owns m_callback. Because ~signal() is defaulted, destroying the signal only releases the vector's references. A surviving connected handle therefore retains the callback and continues reporting connected() until disconnection; scoped_connection differs because its destructor disconnects. The callback_destruction fixture discards the handle before destroying the signal, so it does not cover this case. The retention predates this PR, but the unqualified guarantee is new. Qualify the header and test comments to account for surviving connected handles, and add a characterization test retaining a plain handle beyond the signal's scope.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.