2 minor findings · 4 suggestions
Earlier concerns neither republished nor resolved: 1 minor finding · 1 suggestion. See the Run archive for their assessments.
Findings
[minor] · Concurrent registration can destroy user data under the signal mutex
Concurrent connection creation and destruction can run a user-data destroy callback under the signal mutex, causing a deadlock if it re-enters registration or eligible logging.
Location: src/kernel/bitcoinkernel.cpp:519 (head).
Details and suggested fix
signal::connect() holds m_mutex while pruning, and each connected() probe temporarily owns the existing callback through load(). If another thread disconnects that connection after the load, and no invocation retains it, the probe releases the final reference while still locked. This destroys the lambda's captured data and calls user_data_destroy_callback. The local reference in KernelLogger::Connect() protects only the new subscriber. A destroy callback that creates another connection then relocks the same non-recursive mutex. Logging also reaches that mutex if the entry meets the minimum level and another subscriber keeps delivery enabled. At the default Info level, the disconnect API's preliminary Debug log is filtered out and does not prevent this interleaving. Keep callback references acquired by locked liveness scans alive until after unlocking, including in empty(), and add a concurrent registration/disconnection test with re-entrant teardown. Base kernel teardown explicitly destroyed user data outside its mutex. The race window is narrow, and no current consumer combining concurrent create/destroy with a re-entrant destroy callback was identified, so production impact is unconfirmed.
[minor] · A throwing connection-created log leaks the registered connection
With Debug or Trace delivery enabled, allocation failure while logging "Logger connected." returns null but leaves the callback registered and its user data owned by an unreachable connection.
Location: src/kernel/bitcoinkernel.cpp:955 (head).
Details and suggested fix
btck_LoggingConnection::create() releases its owning unique_ptr, leaving only a raw pointer across the following LogDebug. The connection has already subscribed and incremented m_callback_count. If allocation fails while signal dispatch copies its connection list, the exception occurs outside the handler that swallows application callback exceptions. The outer catch returns nullptr without deleting the connection, so the subscription and count remain, and the promised user-data cleanup never happens. If the payload references caller-scoped state, later callbacks can access that state after it expires. Base retained an owning CallbackHandle across this log and unregistered during unwinding. Construct a local std::unique_ptr<KernelLogger::Connection>, retain it through LogDebug, and release it through btck_LoggingConnection::ref() only on success. This also avoids the public destroy function's extra log during cleanup. No current caller encountering this allocation-failure path was identified, so production impact is unconfirmed.
Optional improvements
[suggestion] · Callback contract omits same-thread reentrancy
The thread-safety requirement does not warn consumers that nested log delivery can reacquire a callback's own non-recursive lock.
Location: src/kernel/bitcoinkernel.h:410 (head).
Details and suggested fix
MaybeLog() invokes the signal directly, so an eligible entry logged by a callback, a kernel function it calls, or a finalizer it triggers is delivered synchronously before the outer invocation returns. This includes the running callback if it remains connected, as logging_callback_reentry_tests expects. A consumer can satisfy the documented thread-safety requirement with std::mutex or Python's threading.Lock and still hang if it holds that lock across work that logs. Document same-thread reentrancy in both btck_LogCallback and the wrapper's Log comment. Warn against holding non-recursive locks across potentially logging work and against logging unconditionally on every invocation, which can recurse without bound. Also narrow "No lock is held" to the logging dispatch lock, consistent with the existing cs_main caveat.
[suggestion] · Destroy-callback contract omits the logging thread's lock context
After disconnection, the final invocation can destroy user data while its logging thread still holds kernel locks, so teardown code needs the log callback's cross-thread-wait restriction.
Location: src/kernel/bitcoinkernel.h:966 (head).
Details and suggested fix
If disconnection leaves an in-flight invocation as the final owner, the signal loop destroys the lambda and its captured user data before returning to the kernel log statement. That statement can hold cs_main, as UpdateTipLog() does. The new destroy documentation already identifies the last-returning thread, but neither it nor the logging destroy-callback parameter documentation explains this lock context. A binding's destroy callback may release host-language references and run finalizers; waiting there for another thread blocked on a kernel lock can deadlock. Explicitly apply the log callback's internal-lock and cross-thread-wait restrictions to logging user-data teardown. Also qualify the lifetime summaries at lines 158–159 and 406–408: dispatch that retained a callback before disconnection may still begin or finish its invocation after the connection is destroyed.
[suggestion] · Concurrency test misses the first-return lifetime boundary
The concurrency test never observes user-data lifetime after one invocation finishes while the other remains blocked, leaving premature destruction at that boundary unchecked.
Location: src/test/kernel/test_kernel.cpp:940 (head).
Details and suggested fix
logging_callback_concurrency_tests checks !destroyed before releasing either invocation and checks destroyed only after both threads join. Its shared release flag lets both callbacks finish before either join returns, so premature destruction after the first return could satisfy both assertions. BlockingLog::LogMessage() also has no member access after its wait that would reliably expose early deletion. Give the invocations separate release gates. Release one, join its logging thread, and assert !destroyed while the second remains blocked. Then release and join the second and assert destroyed. This preserves the existing overlap and non-blocking-disconnect checks while directly testing the documented last-invocation lifetime guarantee.
[suggestion] · Test-only workaround downgrades warnings across two CI builds
The global workaround makes genuine maybe-uninitialized warnings non-fatal throughout the i686 and Alpine musl builds, rather than limiting the exception to the affected test fixtures.
Location: ci/test/00_setup_env_i686.sh:22 (head).
Details and suggested fix
Commit e5c00b4 attributes the GCC 15 false positive to the new std::optional<Logger<...>> fixtures, but both jobs pass -Wno-error=maybe-uninitialized through global CMAKE_CXX_FLAGS. This follows the armhf precedent, yet it also removes automatic failure for genuine diagnostics in unrelated translation units; the warnings remain visible. Prefer a test-local workaround over broadening this downgrade. For example, try std::unique_ptr<Logger<...>> holders, whose reset() preserves the connection-destruction operations these tests exercise, and verify the result with GCC 15 at -O1 before removing the CI flags. Whether that rewrite eliminates the warning is unverified.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [minor]: Callback contract permits unsafe same-thread kernel re-entry (earlier report)
- [suggestion]: Self-destruction docs omit Debug-level recursive delivery (earlier report)