Repository navigation
Enable query profiler under sanitizers - #100242
Conversation
|
Workflow [PR], commit [fa1098d] Summary: ✅
AI ReviewSummaryThis PR enables PR Metadata
Findings
💡 Nits
Tests
Final VerdictStatus: Minimum required actions: fix the |
efbb3ca to
608696b
Compare
f887045 to
6ede5c4
Compare
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
|
The flaky check failure is fixed in #102148, let's update the branch. |
The query profiler was disabled under sanitizers because libunwind's async stack unwinding interferes with sanitizer internals — sanitizers modify %rbp during their own frame-walking, and a profiling signal arriving mid-unwind would crash in libunwind. Replace libunwind with abseil's frame-pointer-based stack unwinding under sanitizers. Abseil's `GetStackTrace` / `GetStackTraceWithContext` use `NO_SANITIZE_ADDRESS/MEMORY/THREAD` attributes and are safe. Key changes: StackTrace.cpp: use `absl::GetStackTrace[WithContext]` under SANITIZER instead of `unw_backtrace` / libunwind. QueryProfiler.cpp: remove the SANITIZER throw guards that disabled the profiler. Skip `hasPHDRCache` check under sanitizers (not needed for frame-pointer unwinding). Skip `sigsetjmp` protection under sanitizers (TSan wraps signal delivery, making `siglongjmp` across its frames unsafe). Server.cpp: bypass `hasPHDRCache` for `TraceCollector` init under sanitizers. Under TSan the PHDR cache is not created (TSan intercepts `dl_iterate_phdr`), but frame-pointer unwinding does not need it. Defines.h, SettingsQuirks.cpp: enable profiler default sample rate and remove the quirk that force-zeroed profiler settings under sanitizers. build_clang_builtin.cmake: build compiler-rt with `-fno-omit-frame-pointer` and `-DCOMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG=OFF` so that sanitizer runtime frames (e.g. TSan interceptors) have frame pointers, allowing abseil's walker to traverse them. sleep.cpp: under TSan, use `nanosleep` instead of `clock_nanosleep`. TSan intercepts `nanosleep` (setting `in_blocking_func`), which causes profiling signals to be delivered immediately rather than deferred. Without this, TSan defers the signal and the saved `ucontext_t` may point to stale stack memory. Tests: remove no-tsan/no-asan/no-ubsan/no-msan tags from query profiler tests. Add a real-time profiler test using `numbers_mt` which reliably produces meaningful traces under TSan. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The abseil StackTrace() path (no ucontext) only produces correct traces when TSan defers the signal — abseil walks from the current stack which happens to include the interrupted code at TSan's interceptor boundary. Under ASan/MSan/UBSan, signals are delivered synchronously, so abseil only captures signal handler frames, missing the interrupted code (e.g. FunctionSleep). Use libunwind with sigsetjmp protection for these sanitizers, same as non-sanitizer builds. The original libunwind crash issue (sanitizer modifying %rbp mid-unwind) is specific to TSan which does concurrent frame-pointer walking. ASan/MSan/UBSan do not have this problem. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
b3e6348 to
80f3dc2
Compare
TSan reported a data race on `optional<TraceCollector>::has_value`: the TraceCollector ctor (called inside `optional::emplace`) starts a worker via `ThreadFromGlobalPool`, whose lambda runs `ThreadStatus::initGlobalProfiler` before the actual function. That calls `Context::hasTraceCollector()`, which reads the optional's engaged byte while `emplace` is still in the middle of setting it on main. Switch the thread to `ThreadFromGlobalPoolWithoutTraceCollector`, which is provided by `ThreadPool.h` for exactly this case (it skips `initGlobalProfiler`). Profiling the trace collector worker itself is pointless anyway. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
TSan flagged a data race on the trace pipe fd: the destructor called `tryClosePipe()` (which closes both ends) before joining the worker thread, so main's `close()` on the read fd raced with the worker's `read()` on the same fd. Move `tryClosePipe()` to after `thread.join()`. The stop byte written earlier in the destructor makes the worker exit normally; only after the worker has exited do we close the fds. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The check that requires checking the return value of `close` greps for ` close(...fd` / ` ::close(` and currently flags any line that mentions those literally — including comments that use them as prose, e.g. "without racing on close() and read() on the same fd". Add a comment filter so lines whose match site is inside a `//`, `///`, or `*` comment are excluded. See https://s3.amazonaws.com/clickhouse-test-reports/PRs/100242/21da94994d3511d3511c781b558a8e60c218a049/style_check/job.log
LLVM Coverage Report
Changed lines: 94.74% (90/95) | lost baseline coverage: 4 line(s) · Uncovered code |
|
Perf tests (ones with red queries): Analysis: |
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/1929 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/1929 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
|
Probably can be resolved by #112008 |
Every `MemorySanitizer` report produced in CI since 2026-05-28 is truncated
to a single line:
==117==WARNING: MemorySanitizer: use-of-uninitialized-value
MemorySanitizer: nested bug in the same thread, aborting.
There is no stack trace, no `SUMMARY` and no origin, so the underlying bug
cannot be located. In the CI database, `msan` checks recorded 1009 reports
with a usable stack in 2026-04 and 0 in 2026-07; `asan`, `tsan` and `ubsan`
reports are unaffected and still carry full stacks.
The regression window matches ClickHouse#100242 (merged 2026-05-28), which enabled the
sampling query profiler for sanitizer builds. Printing an MSan report takes
the sanitizer runtime seconds, because it symbolizes every frame through an
`llvm-symbolizer` subprocess, and it holds `ScopedErrorReportLock` for the
whole time. A profiler signal delivered to that thread meanwhile runs
instrumented code in the handler and trips a second MSan check; compiler-rt
treats a same-thread re-entry into the report lock as unrecoverable, writes
`nested bug in the same thread, aborting.` with `CatastrophicErrorWrite` and
calls `internal__exit`, so the report that was already being written to
`MSAN_OPTIONS=log_path` stops after its header line.
Reproduced with the `arm_msan` binary from master `3885f7b7bbf1`, running the
same query against the same server three times and forcing a sanitizer report
with `max_allocation_size_mb=32 allocator_may_return_null=0`:
- profiler on (default `global_profiler_real_time_period_ns`): `nested bug in
the same thread, aborting.`, 1-line report;
- `<trace_log remove="1"/>` (no profiler at all): full 31-line report;
- `trace_log` on but `global_profiler_*_period_ns = 0` and the per-query
profiler off: full 31-line report.
So it is the profiler timer signals, not the trace collector.
Turn `QUERY_PROFILER_SUPPORTED` off under MSan, next to the existing
TSan-on-macOS exclusion. The trace collector stays enabled: the memory
profiler, `trace_profile_events` and `SYSTEM INSTRUMENT` all feed it from
ordinary code rather than from a signal handler, and other sanitizers keep the
profiler because their checks fire only on genuinely invalid accesses, which
the handler does not perform.
`00974_query_profiler` and `01569_query_profiler_big_query_id` assert that
samples reach `system.trace_log`, so they get `no-msan` back.
This does not fix the uninitialized read that the `BuzzHouse (amd_msan)` run
below hit - that one is unidentifiable as reported. It makes the next
occurrence diagnosable.
CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=3885f7b7bbf1b8791021e1c97ca2e4eea132de04&name_0=MasterCI&name_1=BuzzHouse%20%28amd_msan%29
Related: ClickHouse#100242
Related: ClickHouse#106591
Co-Authored-By: Claude Fable 5 <[email protected]>
Stateless jobs on amd_llvm_coverage lose whole runs to `Timeout exceeded (180 s) while flushing system log 'DB::SystemLogQueue<DB::TraceLogElement>'`. Six different tests died on this signature inside a single coverage job run on 2026-09-05, so it is a job-wide trace_log drain stall rather than a property of any one test. trace_log.symbolize defaults to true, and in-flush symbolization (SymbolIndex::findSymbol + tryDemangle + AddressToLineCache::get, per frame in TraceLogElement::appendToBlock) is what the single flusher thread spends the hardcoded 180 s of SystemLogQueue::waitFlush on. ClickHouse#100242 already fixed that by shipping tests/config/config.d/trace_log_no_symbolize.xml, but its gate probes CXX_FLAGS LIKE '%-DSANITIZER%' and the else arm removes the file again. A coverage build is configured -DSANITIZE= ... -DWITH_COVERAGE=ON, so it carries no -DSANITIZER: coverage was the one stateless flavour left symbolizing at full cost. Probe the dedicated WITH_COVERAGE row of system.build_options instead. Plain -DWITH_COVERAGE never reaches CXX_FLAGS (cmake/sanitize.cmake adds it only under WITH_COVERAGE_DEPTH; the coverage compile flags are applied per-directory), which is why build_option_flag cannot be reused and why tests/clickhouse-test keys off the same row. The new helper keeps the fail-closed contract of its neighbour: a renamed or missing row aborts the install rather than reading as "not a coverage build", and every probe is resolved before any file is touched, so a failing probe cannot leave a half-adjusted config directory. Measured on a debug build, a fresh server per arm (AddressToLineCache is a process-wide static, so a warmed process understates the cost) and an identical workload, timing the first SYSTEM FLUSH LOGS trace_log: 0.35 s with symbolize=false, 0 of 13226 rows symbolized, versus 3.12 s with symbolize=true, 13388 of 13388 symbolized. That is 8.9x, i.e. symbolization is ~89% of flush cost; ClickHouse#100242 measured up to 2.5 minutes for ~180k entries on an instrumented build. This removes the dominant per-row cost without making the 180 s budget unconditional, and deliberately does not touch that constant: raising it is the shape ClickHouse#105484 was closed for. The tests that assert a non-empty symbols or lines column (03150_trace_log_add_build_id, 03150_trace_log_source_lines) already carry no-llvm-coverage, and 00974_query_profiler resolves symbols on read, so nothing regresses; the comments naming the affected flavours are updated to match. One consumer did not resolve on read: the MemoryAllocatedWithoutCheck advisory in tests/clickhouse-test suggests a diagnostic query grouped by the symbols column. Those rows reach trace_log through MemoryTracker -> TraceSender -> TraceCollector, which stamps every row with the config's symbolize value, so the suggested query has collapsed every stack into a single empty bucket on all sanitizer builds since 2026-05-08. It now resolves symbols on read with addressToSymbol, which repairs the guidance for both flavours. Co-Authored-By: Claude Opus 5 <[email protected]>
Linked issues
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
To run tests
Note
Medium Risk
Touches signal-handler stack unwinding and trace pipe shutdown coordination; mistakes here can cause hangs/crashes that are hard to debug, but changes are gated to sanitizer/TSan-specific paths and add safety checks.
Overview
Enables the query profiler in sanitizer builds, switching TSan to frame-pointer-based unwinding (abseil) and adjusting
QueryProfiler/StackTracebehavior to avoiducontext_t/libunwind races while keeping crash-signal unwinding on libunwind.Build and runtime support is updated to require frame pointers (
-fno-omit-frame-pointer), propagate that into bundledcompiler-rt, and linkabsl::stacktrace. Server startup logic is adjusted so profiler/trace collection no longer depends on PHDR cache under TSan.Hardens trace collection shutdown by adding
TraceSenderin-flight/shutdown atomics and makingTraceCollectordrain senders and close the pipe safely; also tweaks TSan sleep behavior, makes severalMemoryTrackersampling knobs atomic, and updates tests/config (disable in-flush symbolization under sanitizer builds, retag/adjust profiler tests and expectations).Reviewed by Cursor Bugbot for commit ad3b8ca. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.6.1.219