Repository navigation
Do not run the LeakSanitizer check on the forced exit path - #114053
alexbakharew merged 8 commits into
Conversation
On ASan builds the server's forced-shutdown branch calls safeExit(0), which calls __lsan_do_leak_check(). That branch is taken precisely because connection handlers and refresh tasks missed the drain timeout, so LSan stops the world and classifies chunks those threads are still using. The reports are unattributable by construction. Two were reported on 2026-08-08 as a uniqExact hash-table "direct leak" (2 MiB on ClickHouse#112846, 4 MiB on ClickHouse#101264). Both are a single allocation with zero indirect leaks, and the two green asan_ubsan jobs on the same commit of ClickHouse#112846 also force-shutdown with connections live while reporting nothing, so neither is an aggregation bug. Since ClickHouse#113608 made previously unattributed sanitizer reports nameable, these compete with real leaks in every stress report. safeExit gets a defaulted run_leak_check parameter, so every existing caller keeps today's behavior, and the two force-exit branches reached while handler threads are still running pass false. A stderr line records that coverage was skipped rather than passed; its wording avoids "<Name>Sanitizer:" so that CI log parsing does not read it as a failure. Keeper's identical-looking branch is left alone on purpose: it calls server_pool.joinAll() first, so no handler is still running there and this report class cannot arise. The client's SIGINT/SIGQUIT handler keeps the default. Clean shutdowns never reach safeExit, so they keep full leak coverage through the ordinary at-exit check. Two mechanisms that look plausible were measured and rejected. __lsan_disable() does not suppress the check: it is an allocation-time per-thread flag, and a probe still reported the leak. Omitting the call does not re-arm the at-exit check either: that check is installed with Atexit(), which _exit() bypasses, so omission can only remove reports, never add any. Co-Authored-By: Claude Fable 5 <[email protected]>
The client's SIGINT/SIGQUIT handler calls safeExit from signal context while query threads are still alive, so it is a carrier of the same invariant as the server's forced-shutdown branch and it kept running the leak check. That is not hypothetical: 02435_rollback_cancelled_queries.sh already works around the check deadlocking there when the interrupt lands while the allocator lock is held. The skip notice moves from fputs to write(2), which is async-signal-safe, since it now runs from that handler. <cstdio> is no longer needed. Keeper still calls the one-argument form on purpose, and the unit test now exercises that form directly instead of forwarding an explicit flag, so flipping the default would be caught. The skip arm also asserts the notice is present, so deleting it would be caught too. Both gaps were silent before. Co-Authored-By: Claude Fable 5 <[email protected]>
The forced-exit paths skip the LeakSanitizer check because LSan stops the world and classifies chunks that still-running threads own. Two of those paths write a one-line notice to stderr so a reader of a stress log can tell coverage was skipped rather than passed. The client's SIGINT handler must not: there stderr is program output. tests/clickhouse-test fails a .sh test on any non-empty client stderr, and where a test merges the two streams the line lands in the diffed output. 02435_rollback_cancelled_queries does both -- it pipes with 2>&1 and its documented ASan path reaches this handler -- so announcing the skip made a green test fail its reference. Replace the boolean with a three-state LeakCheck enum so no call site can pick an incoherent combination: Run (default), SkipAndReport for the server paths whose stderr is a log file, SkipQuietly for the signal handler. Keeper still calls the one-argument form and keeps running the check, having already joined its pools. Each enumerator gets its own gtest arm, and each was shown to be load-bearing by a mutation that reddens exactly one of them. Co-Authored-By: Claude Fable 5 <[email protected]>
clickhouse-local reaches the same forced-exit branch as the server but, unlike the server, never redirects stderr: `logger.stderr` is set in BaseDaemon (src/Daemon/ BaseDaemon.cpp:332) and clickhouse-local does not use it, so fd 2 stays whatever the invoking shell gave it, i.e. program output. Measured: a clickhouse-local that exits on its own while an external client still holds a connection to its TCP listener takes the branch and writes the notice to its stderr. Without LSAN_OPTIONS noise the process's entire stderr is that one 61-byte line, and tests/clickhouse-test:3373 fails a test on any non-empty stderr even at rc=0. The only allow-list there, IGNORED_SANITIZER_ERRORS, is applied to fatal_sanitizer_prefix* files only; self.stderr_file is concatenated unfiltered at :3302, so an allow-list entry would not cover this path. Same reasoning as the client's signal handler, which already passes SkipQuietly. The server keeps SkipAndReport: its stderr is redirected to stderr.log, which is where a stress-report reader looks for the leak report the skip replaces. Also rewrite the comment above the dispatch in safeExit(): the old text described only the Run arm while sitting above the whole if/else. The load-bearing invariant for the skip arms is that _exit(2) bypasses atexit, so skipping does not defer the report to LSan's at-exit handler - it skips it. And drop two comments that named the client as the only quiet caller, now that clickhouse-local is one as well.
The CI sanitizer detector (ci/jobs/scripts/clickhouse_proc.py) opens an open-ended sed range at the first stderr line containing "anitizer", prints everything from there to EOF, and removes a closed allow-list of benign lines. Anything else surviving head -n 1 becomes a BLOCKER job failure. safeExit()'s "Not running the leak check: other threads are still running." notice is not sanitizer output and records a check that was skipped, so it can never itself be a report - but once the range is open it survives the allow-list and gets blamed. The range does open benignly: the __asan_handle_no_return block's "For details see google/sanitizers#189" line matches "anitizer" and is removed only after the range has already opened. That shape has reached this detector before and produced exactly this class of spurious "Unknown error / Lost connection to server" failure - twice, which is why all four of that block's lines are already allow-listed (3955f5d, 25e970d). Add the notice to that allow-list, matched as a whole line (grep -F -x). The other entries are substrings because they are prefixes of longer lines, but a substring test here would drop any line merely containing the notice, so a report that shared a line with it would be silently lost - the same class of CI signal loss this change exists to stop. The notice can only ever be a complete line: safeExit() writes one fixed buffer, newline included, in a single write(2). tests/clickhouse-test needs no counterpart. Its IGNORED_SANITIZER_ERRORS is applied only to the sanitizer runtime's log_path and the client's --client_logs_file, never to the test's own stderr, and the two carriers that runner observes (clickhouse-local, the client's signal handler) skip the check quietly and write nothing. The new ci/tests test drives the real pipeline, reassembled from the module's own AST so that editing the pipeline breaks the test rather than silently bypassing it. Its arms cover the notice alone, the multi-server layout where sed concatenates several stderr*.log files so the range opens in one and the notice sits in the next, and - the ones that matter - that a genuine LeakSanitizer report is still blamed, whether on its own line or sharing one with the notice, and that a line merely resembling the notice is not filtered, so this cannot grow into a blanket silencer.
The notice text exists in three places: safeExit() writes it, the CI detector filters it out of the sanitizer-hit scan, and the tests feed it through that detector. The filter is `grep -a -v -F -x`, a whole-line match, so the three copies have to agree byte for byte. Nothing enforced that. Rewording the emitted line, or its punctuation, therefore left every test arm green while the filter silently stopped matching the real line - and the notice would then survive to `head -n 1` and fail the job as a BLOCKER sanitizer hit, on every forced-shutdown stress run. The gtest did not catch it either: it asserted a prefix, which survives any edit to the tail. Both bindings now derive from base/base/safeExit.cpp: the pytest extracts the message[] literal and asserts the pipeline's filter equals it, and the gtest matches the complete line including the newline that is part of the single write(2). Either copy drifting now fails a test that names both files. Verified by mutating each copy in turn: with only the producer changed the old arms all stayed green while the real filter no longer matched, and the new assertions fail on either side of the drift.
Internal second-model reviewFindings of the internal review of this change, and their disposition. First round:
Later rounds, on the CI-side half:
Final round, both findings rejected, with the reasoning that settled them:
Also verified and left alone: One behavior change worth flagging in review rather than hiding: Weighed and not treated as blocking: |
Pre-PR validation gate
|
|
cc @vitlibar @thevar1able, could you review this? On ASan the forced-shutdown branch ran |
|
Workflow [PR], commit [3e25d0a] Summary: ✅
AI ReviewSummaryThis PR teaches Final Verdict✅ No findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 7/11 (63.64%) · Uncovered code |
Build profile diff (arm_release)No arm_release build profile data for commit 3e25d0a - the build was skipped, reused from cache, or predates profile upload. |
CI finish ledger - e4d4df9Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task CI is fully finished on this head: 175 check-runs, 0 queued/in_progress,
Neither is caused by this PR: it only removes the Session id: cron:our-pr-ci-monitor:20260810-040000 |
@ alexbakharew asked on both LeakCheck::SkipQuietly call sites why the comment does not state that the LeakSanitizer check is skipped. Each of the three comments now leads with the fact, then the invariant that requires it: which memory is still owned at that point (clickhouse-local, server) or that the leak check deadlocks in signal context under the allocator lock (client), and why the notice is quiet or reported there. Comments only; no behaviour change. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112846&sha=2e6a38112ad4dacef62f5cc4cdb396cc297282eb&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29 Related: ClickHouse#112846
CI finish ledger for 3e25d0aCI is fully finished on this head and fully green: 176 check-runs, 0 queued/in_progress, No failure rows, so nothing needs an owner. The two failures owned on the previous head Session id: cron:our-pr-ci-monitor:20260812-210000 |
Related: #112846
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
On ASan builds the server's forced-shutdown branch calls
safeExit(0), which runs__lsan_do_leak_check(). That branch is taken precisely because handlers or refresh tasks missedthe drain timeout, so the check stops the world while those threads are mid-query and classifies
chunks they still own, producing unattributable reports.
Two were reported on 2026-08-08 as a
uniqExacthash-table "direct leak" (2 MiB on #112846,CI report;
4 MiB on #101264): each a single allocation with zero indirect leaks, while two green
asan_ubsanjobs on the same commit also force-shutdown with connections live and reportnothing. Since #113608 made such reports nameable, they compete with real ones.
safeExittakes a second parameter, aLeakCheckenum defaulted toRun, so existing callersare unchanged. The three callers reached while other threads still run pass a skip:
Server.cppwrites one stderr line recording that coverage was skipped rather than passed;
clickhouse-localand the client's SIGINT/SIGQUIT handler skip silently, since neither redirects fd 2, so a
notice there would be program output read as a test failure. Keeper's identical-looking branch is
unchanged: it calls
server_pool.joinAll()first. Clean shutdowns never reachsafeExit.That notice is allow-listed in the one scanner that can see it,
sanitizer_hitsinci/jobs/scripts/clickhouse_proc.py, matched as a whole line so a report sharing a line with itis still blamed; a new
ci/teststest pins that.tests/clickhouse-testneeds none: itsIGNORED_SANITIZER_ERRORSfilters only the sanitizer runtime'slog_pathfiles, and thecarriers that runner sees skip quietly.
Validated on an ASan build: the notice appears on the forced branch and no leak report does,
while the same tree with the guard removed runs the check. Side effect:
_exit()drops the asynclogger queue, so
Will shutdown forcefully.is now missing on ASan builds, as it already is whereno check delays the exit.
Version info
26.8.1.1312(included in26.8and later)