Review report

core: PR #34775

3 suggestions

Earlier concerns neither republished nor resolved: 1 minor finding · 2 suggestions. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · Callback documentation does not define supported re-entry or self-destruction

The documentation still forbids all kernel API calls, leaving bindings without a contract for re-entrant logging; destroying the connection from its own callback hangs, though no affected binding was identified.

Location: src/kernel/bitcoinkernel.h:432 (head).

Details and suggested fix

The change allows callbacks to run outside m_mutex, so a kernel call made by a callback can trigger logging that re-enters the callback on the same thread. The callback documentation still says it must not call any kernel API function because that may deadlock, leaving bindings without a contract for this behavior.

One re-entrant call does hang: destroying a logging connection from inside its own callback. Log() increments m_in_flight before invoking the callback and decrements it only after the callback returns. UnregisterCallback() waits for m_in_flight to reach zero, but that count includes the current invocation. This is not a regression: before this change, the same call re-locked the non-recursive m_mutex held by Log().

Document the intended contract. If finalizer-triggered kernel calls are supported, say that logging may re-enter the callback on the same thread and that the callback must not destroy its own connection. The behavior change is established, but no binding that finalizes its connection wrapper on the callback thread was identified, so production impact is unconfirmed.


Link

[suggestion] · Concurrent log writes are not guaranteed to preserve whole lines

Formatting each line before one std::cout insertion does not guarantee that concurrent writes will not interleave; any impact is limited to the demo executable and test logger.

Location: src/bitcoin-chainstate.cpp:57 (head).

Details and suggested fix

Callbacks can now run concurrently, so KernelLog::LogMessage and TestLog::LogMessage may write to std::cout at the same time. The C++ standard guarantees that concurrent use of synchronized std::cout is free of data races, but does not guarantee that a single operator<< is indivisible or that characters from different calls will not interleave. No interleaving has been shown on a specific build, and common standard libraries may already perform this insertion as one write. To guarantee the comment's claim, guard the final std::cout << line.str() in both writers with a function-local static std::mutex.


Link

[suggestion] · Concurrency test can hang instead of reporting a failure

If callbacks are serialized again or the expected INFO log is absent, the test waits indefinitely and may end only through an external timeout.

Location: src/test/kernel/test_kernel.cpp:810 (head).

Details and suggested fix

logging_callback_concurrency_tests waits without a deadline for both logging threads to enter the callback. If callbacks become serialized, or the signet-challenge LogInfo is no longer emitted at INFO, only one thread may enter and the loop never exits. The test then hangs until an external timeout. Bound the wait with a deadline; on timeout, set and notify released, join the threads, and then fail with a diagnostic. Joining first avoids destroying std::thread objects that are still joinable.


Coverage details

Earlier concerns

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