Repository navigation
Stop the asynchronous logging threads at clickhouse-local exit - #112753
alexey-milovidov wants to merge 1 commit into
Conversation
Unlike the server, where `~BaseDaemon` calls `stopLogging`, `LocalServer` never stopped the `AsyncLogger`/`AsyncTextLog` threads started by `Loggers::buildLoggers`, so `OwnAsyncSplitChannel::close` was never called and the threads were still consuming the log queues while `exit` ran static destructors. ThreadSanitizer intermittently reported them as leaked threads at exit and aborted the process (sanitizers run with `abort_on_error=1`), which failed the "Scraping system tables" CI step for every system table dumped by `clickhouse-local`. Closes: #110816 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [ad912f6] AI ReviewSummaryThis PR fixes Final Verdict✅ No blocking findings. |
Algunenano
left a comment
There was a problem hiding this comment.
Nice catch. LocalServer is the only one not inheriting from BaseDaemon, which makes this necessary
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 3/3 (100.00%) · Uncovered code |
`clickhouse-local` never stopped the asynchronous logging threads (one `AsyncLogger` per log channel plus `AsyncTextLog`) started by `Loggers::buildLoggers`. Unlike the server, where `~BaseDaemon` calls `stopLogging`, `LocalServer` had no such call, so `OwnAsyncSplitChannel::close` never ran and the threads were still consuming the log queues while `exit` ran static destructors. Under ThreadSanitizer the unjoined threads surface at exit as a `thread leak` report on `AsyncLogger`, and since sanitizers run with `abort_on_error=1` the report aborts `clickhouse-local`. That made the `Scraping system tables` CI step report every `system.*_log` dump of an affected run as failed. The `amd_msan` `use-of-uninitialized-value` in `OwnPatternFormatter::formatExtended` is the same shutdown race caught in the act: the `AsyncLogger` thread was still formatting a message using Poco's static priority-name strings after `exit` had destroyed them. The fix mirrors `BaseDaemon`: `~LocalServer` stops and joins the asynchronous logging threads (`OwnAsyncSplitChannel::close` flushes the queues before joining), so they never overlap with static destruction. Originally submitted as #112753 against the first version of this change. Folded in here because that version was reverted in #112793 and is reintroduced by this pull request, so the fix must land together with it. Closes: #110816
|
Superseded by #112803. #107363, the change that exposed this shutdown race, was reverted in #112793 and is being reintroduced by #112803. Since the fix has to land together with it rather than after it, this commit was folded into that pull request as Closing in favour of #112803, which now carries |
Closes: #110816
Related: #110099
Related: #111979
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
clickhouse-localnever stopped the asynchronous logging threads (oneAsyncLoggerper log channel plusAsyncTextLog) started byLoggers::buildLoggers. Unlike the server, where~BaseDaemoncallsstopLogging,LocalServerhad no such call, soOwnAsyncSplitChannel::closenever ran and the threads were still consuming the log queues whileexitran static destructors — verified with gdb breakpoints and strace:closeis never called and the threads are terminated byexit_groupinstead of being joined.In CI this intermittently fails the "Scraping system tables" step, which dumps every
system.*_logtable with a separateclickhouse-local --config-file=/etc/clickhouse-server/config.xmlinvocation. Under ThreadSanitizer the unjoined threads surface at exit asand since sanitizers run with
abort_on_error=1, the report abortsclickhouse-local, so every table dump in an affected run is reported as failed (about 33 such failures acrossamd_tsanchecks since 2026-07-21).The MSan
use-of-uninitialized-valuefailures of the same CI step onamd_msanare the same shutdown race, caught in the act.OwnPatternFormatter::formatExtendedreads Poco's static priority-name strings (writeString(getPriorityName(priority), wb)), and the MSan origin shows they had already been destroyed byexit(withpoison_in_dtor=1, destroyed objects are poisoned) while theAsyncLoggerthread was still formatting a message:The fix mirrors
BaseDaemon:~LocalServerstops and joins the asynchronous logging threads (OwnAsyncSplitChannel::closeflushes the queues before joining), so they never overlap with static destruction. Verified with strace that theAsyncLogger/AsyncTextLogthreads now exit and are joined before the finalexit_group, on both the success and the error path, with exit codes unchanged.No test is added: every
clickhouse-localinvocation in the sanitizer stateless CI runs exercises this path.