Skip to content

Disable the sampling query profiler under Memory Sanitizer - #113107

Merged
alexey-milovidov merged 53 commits into
masterfrom
msan-disable-query-profiler
Sep 5, 2026
Merged

alexey-milovidov merged 53 commits into
masterfrom
msan-disable-query-profiler

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

Related: #100242
Related: #106591

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.

No stack trace, no SUMMARY, no origin — so no MSan failure can be located. In the CI database, msan checks recorded 1009 reports with a usable stack in 2026-04 and 0 in 2026-07, while asan, tsan and ubsan reports are unaffected and still carry full stacks.

The regression window matches #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 built 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:

configuration result
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 with stack
trace_log on, global_profiler_*_period_ns = 0, per-query profiler off full 31-line report with stack

So it is the profiler timer signals, not the trace collector.

This turns 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. 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. The other profiler and trace_log tests either already carry no-msan, exercise the memory profiler / trace_profile_events / SYSTEM INSTRUMENT (unaffected), or make no assertion on sample counts.

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

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Workflow [PR]
Sync PR [sync-upstream/pr/113107]

Version info

  • Merged into: 26.9.1.811 (included in 26.9 and later)

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 #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: #100242
Related: #106591

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e279910]

Summary: ✅


AI Review

Summary

This PR disables the sampling query profiler under MemorySanitizer, aligns the exposed defaults with that unsupported state, rejects explicit non-zero profiler periods on the affected settings surfaces, and updates the affected tests accordingly. The core change looks coherent, but the new NOT_IMPLEMENTED contract is still not directly proved by the test suite for the regular query settings or the server-wide profiler settings.

Tests
  • ⚠️ query_profiler_*_period_ns: the updated stateless coverage now strips or skips these settings on MSan, but I do not see a focused regression test that a positive query-level period is rejected with NOT_IMPLEMENTED. A tiny MSan-aware stateless case using SET or per-query SETTINGS would close that gap.
  • ⚠️ global_profiler_*_period_ns: the updated integration/config setup now starts from 0 on MSan and skips before asserting that a positive server config fails. A focused config-load or integration check that restart/config parsing rejects non-zero global profiler periods on MSan would prove the new behavior.
Final Verdict

⚠️ Request changes: the implementation looks consistent, but the new MSan rejection paths for query and server profiler settings still need focused regression coverage.

LLVM Coverage Report

Measured on commit e279910.

Metric Baseline Current Δ
Lines 88.60% 88.60% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 80.90% 81.00% +0.10%

Changed lines: Changed C/C++ lines covered: 87/88 (98.86%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 3, 2026
alexey-milovidov and others added 2 commits August 4, 2026 09:07
With `QUERY_PROFILER_SUPPORTED` compiled out under Memory Sanitizer, tests
that rely on profiler signals to exercise their regression pass vacuously
on MSan instead of testing anything:

- `02466_distributed_query_profiler` needs the signals to hit the `EINTR`
  path in `MultiplexedConnections::getReplicaForReading()`.
- `04507_mysql_connect_timeout_under_profiler` needs them to interrupt
  `poll` so `MYSQL_OPT_CONNECT_TIMEOUT` deadline handling is exercised.
- `01091_query_profiler_does_not_hang` guards against a hang under a
  profiler signal storm, which is never produced without the profiler.

Tag them `no-msan` so the MSan matrix reports them as skipped rather than
as green tests that no longer cover their bug.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=8f0f86485d192241fd2ed5bc0f5cb0b7630d244c&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

02703_max_local_read_bandwidth failed on pread_threadpool: the query was correctly throttled (duration ≥ 7 s, QueryLocalReadThrottlerBytes > 8e6) but QueryLocalReadThrottlerSleepMicroseconds came out 0 — the sleep time seems to be lost/not attributed to the query when reading via the thread pool. CI reruns passed (labeled flaky) and it is unrelated to this PR, which only touches the query profiler under MSan.

@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Acknowledged - investigating why QueryLocalReadThrottlerSleepMicroseconds came out 0 on pread_threadpool while the byte counter and the duration both indicate throttling. I will follow up here with a PR, or with my findings if it turns out not to be an attribution bug.

@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Fixing PR: #113365

The sleep time is not lost and not misattributed to a pool thread. In that failure
QueryLocalReadThrottlerBytes exceeded 8e6 while its sibling sleep counter was 0, and both are
charged through the same CurrentThread::getProfileEvents a few lines apart in
Throttler::throttle, so a thread detached from the query would have lost both. There is also no
pool thread to lose it on: for pread_threadpool the throttle call runs on the consuming pipeline
thread in AsynchronousReadBufferFromFileDescriptor::nextImpl, and ThreadPoolReader never
throttles.

The 4th assertion is a coupled oracle instead. The bytes counter is incremented unconditionally
(Throttler.cpp:63-64), the sleep counter only inside if (block) (:78-82), and block requires
tokens_value < 0 (:70). The token bucket only goes negative while bytes arrive faster than the
cap, so when a contended runner's read rate falls to about the cap the throttler correctly does not
sleep, and 1 1 1 0 is the engine behaving as designed.

The fixture had no margin left. M is the decimal suffix (01039_test_setting_parse pins that
'12M' is 12000000 and '31Mi' is 32505856), so the cap was 1e6 B/s and the 8 MB payload owed
exactly 7.0 s, which is exactly what the query_duration_ms >= 7e3 column also demands. The
threshold had already been walked down twice for this same flake, in fdfb1eda55b0c2e and
263be33297a2ada, so a third relaxation is not a fix. #113365 instead co-reduces the payload and the
cap so the owed sleep goes from 7.0 s to 9.0 s while wall clock stays comparable, which is what was
merged for the sibling 04103_user_network_bandwidth_throttler in #106680. Derived from the fixture
constants and the token bucket, the sleep assertion used to break once the natural read rate fell
below 2.284 MB/s and now breaks below 0.291 MB/s.

No source change: the throttler behaved correctly at every arrival rate I measured.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Aug 4, 2026
…bandwidth

The headroom fix lowered both byte checks from `> 8e6` to `> 1.5e6` along with
the payload, but 2e5 `UInt64` rows are 1.6e6 raw bytes, so `> 1.5e6` left
100600 measured bytes of slack. That is a real loss of contract: the two byte
columns exist to prove the whole scan went through the local-read throttler,
and a regression letting about 100 KB bypass it would still have printed
`1 1 1 1`.

Measured on the fixture (all three read methods, warm and cold mark cache):
`ReadBufferFromFileDescriptorReadBytes` and `QueryLocalReadThrottlerBytes` are
both 1600600 warm and 1600777 cold, deterministic over 9 runs. `CODEC(NONE)`
makes the compressed file the raw payload plus a 25-byte header per compressed
block, so the counter is always strictly above 1.6e6. Raising both checks back
to `> 1.6e6` restores the same relative margin the pre-fix fixture had against
`> 8e6` (0.0375% versus 0.0381%).

Verified the tightened threshold is not vacuous by shrinking the payload: at
187500 rows (the 100 KB bypass the reviewer described) the counter is 1500746,
which passes `> 1.5e6` and fails `> 1.6e6`; even 199900 rows, 800 bytes short,
is caught. The sleep oracle this PR fixes is unaffected: the test passes three
times with no injection and twice under a rate injection at 1.05x of its own
cap, which is the arm that reproduces a loaded runner.

CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=8f0f86485d192241fd2ed5bc0f5cb0b7630d244c&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29
Related: ClickHouse#113107
…profiler

# Conflicts:
#	src/Common/QueryProfiler.h
…iler

The flaky check on amd_asan_ubsan failed 4 of 144 runs of this test: the
first sub-test samples `sleep(0.5)` with a 100ms real-time profiler
period, which gives only ~5 signals, and under a loaded sanitizer server
all of them can be lost, leaving 0 rows in `system.trace_log`. Use a
10ms period (~50 chances), matching the hardening already applied to
the `numbers_mt` sub-test.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=fa49e4387e79325101ddf6f0c937fa99a3130e8b&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29
PR: #113107
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update:

  • Merged master (the PR was conflicting: master added the OS_HAS_SIGNAL_HANDLERS condition for Emscripten to the same #if in src/Common/QueryProfiler.h; both conditions are now combined).
  • Flaky check (amd_asan_ubsan) failed 4/144 runs of 00974_query_profiler: the sleep(0.5) sub-test samples at a 100ms period, only ~5 signal opportunities, and under the loaded sanitizer server all of them were occasionally lost. Shortened the period to 10ms, matching the hardening already applied to the numbers_mt sub-test. Verified locally: 10/10 runs pass.
  • Stress test (arm_release) is the known harness flake — the cannot_allocate_thread_fault_injection_probability verification query in stress.py timed out (exit 159) before any tests ran. Fix is in progress: Do not run the server-side AST fuzzer on the stress harness's own queries #113248

pull Bot pushed a commit to peijunlin2008/ClickHouse that referenced this pull request Aug 5, 2026
Corrected narrative for the fix in a2a3a41, which restores the
throttler rate headroom in `02703_max_local_read_bandwidth`, plus the
reference to the pull request that surfaced the flake appended to the test's
leading comment. The executable content of the test is byte-identical to
a2a3a41.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=8f0f86485d192241fd2ed5bc0f5cb0b7630d244c&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29
Related: ClickHouse#113107

The test intermittently failed on `pread_threadpool` with only its 4th column
wrong (`1 1 1 0`): the query was demonstrably slow and all bytes had passed
the throttler, but `QueryLocalReadThrottlerSleepMicroseconds` came out 0.

The 4th assertion is a coupled oracle. `Throttler::throttle` increments the
bytes counter unconditionally (`Throttler.cpp:63-64`), but the sleep counter
only inside `if (block)` (`:78-82`), and `block` requires `tokens_value < 0`
(`:70`). The token bucket (`:110-125`) only goes negative while bytes arrive
faster than the cap, so once a loaded runner's read rate falls to about the cap
the throttler correctly does not sleep and the assertion fails.

The fixture had no margin to lose. `M` is the decimal suffix in
`readTextWithSizeSuffix` (the binary form needs a trailing `i`, as
`01039_test_setting_parse` pins), so the old cap was 1 MB/s = 1e6 B/s and the
8 MB payload owed exactly (8e6 - 1e6) / 1e6 = 7.0 s. That is exactly what the
`query_duration_ms >= 7e3` column also demands, so column 1 was passing on
unrelated overhead, and column 4 had only 2.0x over its 3.5 s threshold. The
pre-existing comment `(8-1)/1=7 seconds` was right; the fixture's problem was
the absent margin, not the arithmetic.

The sleep time is not lost or misattributed to a pool thread. In the reported
failure `QueryLocalReadThrottlerBytes` exceeded 8e6 while its sibling sleep
counter was 0, and both are charged through the same
`CurrentThread::getProfileEvents` a few lines apart in `Throttler::throttle`,
so a thread detached from the query would have lost both; the bytes recorded,
therefore the thread was attached and the sleep branch simply never ran.
Structurally there is also no pool thread to lose it on: for `pread_threadpool`
the throttle call runs on the consuming pipeline thread in
`AsynchronousReadBufferFromFileDescriptor::nextImpl`, and `ThreadPoolReader`
never throttles.

The change co-reduces the payload (1e6 -> 2e5 rows) and the cap
(1e6 -> 160000 B/s), which raises the owed sleep from 7.0 s to 9.0 s at
comparable wall clock: 1.29x over the duration floor, 2.57x over the sleep
threshold, and the read rate must degrade 6.25x further before the token
bucket stops going negative. The two byte thresholds drop 8e6 -> 1.5e6, which
still requires 93.75% of the nominal payload to pass through the throttler.
All four assertions, both time thresholds and the reference file are unchanged.
This is the same fix that was merged for the sibling
`04103_user_network_bandwidth_throttler` in ClickHouse#106680 (issue ClickHouse#103422).

Reproduced deterministically by capping the arrival rate with
`max_execution_speed_bytes` and `max_threads=1`: the unmodified test prints
`1 1 1 0` on all three read methods, and `1 1 1 1` with the injection absent.
The modified test stays green under the same injection, and also at arrival
rates below its own cap. 50/50 clean local runs; runtime 23.9 s -> 28.3 s.

No source change: the throttler behaved correctly at every arrival rate
measured, so there is no product defect here.

Co-Authored-By: Claude Fable 5 <[email protected]>
The flaky check (amd_asan_ubsan) still failed 3/144 runs after shortening the
profiler period to 10 ms, so the loss is not per-signal chance. Profiler samples
are sent to the trace pipe with WriteBufferFromFileDescriptorDiscardOnFailure over
a non-blocking pipe: when a concurrent sample-heavy query (e.g. the numbers_mt
sub-tests of another instance of this test in the flaky check) keeps the pipe full,
samples are silently dropped. The single sleeping thread produces only ~50 samples,
so all of them can be lost at once, while the sample-heavy numbers_mt sub-tests
passed in the same failing runs.

Sleep in 16 threads (one single-row block per thread via numbers_mt(16) with
max_block_size = 1) instead of one: an order of magnitude more samples, and the
sub-test also survives a single thread failing to create its profiler timer.
The reference output is unchanged.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=d0770a05d6c86a28d969b630d928dc4899eb8a35&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29
PR: #113107

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update:

  • The flaky check (amd_asan_ubsan) still failed 3/144 runs of 00974_query_profiler after shortening the profiler period to 10 ms, so the loss is not per-signal chance. Root cause of the remaining flakiness: profiler samples are sent to the trace pipe with WriteBufferFromFileDescriptorDiscardOnFailure over a non-blocking pipe, so when a concurrent sample-heavy query (e.g. the numbers_mt(1e9) sub-tests of another instance of this test in the flaky check) keeps the pipe full, samples are silently dropped. The single sleeping thread produces only ~50 samples, so all of them can be lost at once — which also explains why the sample-heavy numbers_mt sub-tests passed in the same failing runs.
  • Fixed in 19ca09a by sleeping in 16 threads (one single-row block per thread via numbers_mt(16) with max_block_size = 1): an order of magnitude more samples, and the sub-test also survives a single thread failing to create its profiler timer (ThreadStatus::initQueryProfiler swallows that error and runs the query unprofiled). The reference output is unchanged.
  • Verified locally: 10/10 clean runs, 8/8 under a synthetic trace-pipe flood, and identical output under both analyzers.

@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e27991011 with master 8627fa22f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

10 translation units recompiled, 54 s compile time in total, 10 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +3.2 s (+6%) in total before that adjustment.

Job report

alexey-milovidov added a commit to azat/ClickHouse that referenced this pull request Aug 6, 2026
The flaky check (amd_asan_ubsan) failed 3 runs of `00974_query_profiler` even
after shortening the profiler period to 10 ms: the `sleep(0.5)` sub-test got
0 `FunctionSleep` samples with `trace_type = 'Real'`. Profiler samples are
sent to the trace pipe with `WriteBufferFromFileDescriptorDiscardOnFailure`
over a non-blocking pipe: when a concurrent sample-heavy query (e.g. another
instance of this test in the flaky check, or the suite-wide memory sample
profiler this PR enables) keeps the pipe full, samples are silently dropped,
and the single sleeping thread produces so few of them that all can be lost
at once, while the sample-heavy `numbers_mt` sub-tests passed in the same
failing runs.

Sleep in 16 threads (one single-row block per thread via `numbers_mt(16)`
with `max_block_size = 1`) instead of one: an order of magnitude more
samples, and the sub-test also survives a single thread failing to create
its profiler timer. The reference output is unchanged. Same fix as in
ClickHouse#113107 (verified there locally
10/10 and 8/8 under a synthetic trace-pipe flood).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=88405&sha=f5c9438a6df42a63494bba778b56fbe1a3191f10&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29
PR: ClickHouse#88405

Co-Authored-By: Claude Fable 5 <[email protected]>
…974_query_profiler

The sleep sub-test kept failing in the flaky check even after running the
sleep in 16 threads: profiler samples travel over a lossy channel by design.
The signal handler drops samples beyond 100 concurrent invocations
(`QueryProfilerConcurrencyOverruns`) and on timer overruns
(`QueryProfilerSignalOverruns`), and `TraceSender` writes to the trace pipe
with `WriteBufferFromFileDescriptorDiscardOnFailure`, which silently discards
samples when concurrent sample-heavy queries keep the pipe full. Under the
flaky check load, all samples of a short mostly-idle query can legitimately
be lost, so no amount of extra sleeping threads makes the `system.trace_log`
assertion reliable.

Assert on the query's ProfileEvents from `system.query_log` instead: every
delivered profiler signal increments exactly one of `QueryProfilerRuns`,
`QueryProfilerSignalOverruns` or `QueryProfilerConcurrencyOverruns` in the
signal handler itself, so their sum proves the real time profiler fires for
an off-CPU (sleeping) query regardless of trace delivery. End-to-end delivery
to `system.trace_log` and symbolization remain covered by the CPU-bound
sub-tests.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=19ca09a8b440370782fc8ed177db305cecbd6b6c&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29
PR: #113107

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update:

  • The flaky check (amd_asan_ubsan, and the private sync's s3 storage, meta in keeper variant) still failed on 00974_query_profiler after running the sleep in 16 threads: the sleep sub-test again produced 0 rows in system.trace_log. Profiler samples travel over a lossy channel by design — the signal handler drops them beyond 100 concurrent invocations (QueryProfilerConcurrencyOverruns) and on timer overruns (QueryProfilerSignalOverruns), and the trace pipe silently discards writes when full (WriteBufferFromFileDescriptorDiscardOnFailure) — so under the flaky-check load all samples of a short mostly-idle query can legitimately be lost, and no amount of extra sleeping threads makes the trace_log assertion reliable.
  • Fixed in bc61503: the sleep sub-test now asserts on the query's ProfileEvents from system.query_log instead. Every delivered profiler signal increments exactly one of QueryProfilerRuns, QueryProfilerSignalOverruns or QueryProfilerConcurrencyOverruns inside the signal handler, so their sum proves the real time profiler fires for an off-CPU (sleeping) query regardless of trace delivery. End-to-end delivery to system.trace_log and symbolization remain covered by the CPU-bound sub-tests. Verified locally: 10/10 sequential runs and 3 rounds of 4 parallel instances all pass.
  • No unresolved review threads; AI Review: no material findings. The CH Inc sync red was the same test in the private flaky check, so the new run after this push should clear both.

…de profiler

The stateless test harness enables a serverwide profiler with a 1 second
period (serverwide_trace_collector.xml), and the `QueryProfilerRuns` /
`QueryProfilerSignalOverruns` / `QueryProfilerConcurrencyOverruns` counters
are shared between it and the per-query profiler, so the previous `> 0`
assertion could pass even if the per-query profiler never started. Require
`> 64` instead: the serverwide profiler contributes at most ~1 real time tick
per thread over the 0.5 second query (measured 7-10 locally with the
per-query profiler disabled), while the 10ms per-query profiler delivers
~800 signals across the 16 sleeping threads.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update:

  • Addressed the AI review Major: the sleep sub-test's oracle now requires QueryProfilerRuns + QueryProfilerSignalOverruns + QueryProfilerConcurrencyOverruns > 64, a count the harness's 1-second serverwide profiler (serverwide_trace_collector.xml) cannot reach. Measured locally with the serverwide profiler enabled and the per-query profiler disabled, the counters reach only 7–10 over the 0.5-second query (at most ~1 real-time tick per thread, no CPU ticks while sleeping), while the 10 ms per-query profiler delivers ~800 signals across the 16 sleeping threads. Verified 5/5 locally with the harness's serverwide profiler periods active.
  • The flaky check (all variants) passed on the previous commit — the loss-proof counter oracle resolved the 00974_query_profiler flakiness.
  • Build (arm_release) red is the fleet-wide build_profile_hook.py LogCluster writer outage, tracked in Build post-hook fails fleet-wide: build-profile INSERT into the CI logs cluster rejected with MEMORY_LIMIT_EXCEEDED #113408 (mitigation merged, readiness-probe follow-up in Retry the LogCluster readiness probe inside the INSERT retry loop #113592) — unrelated to this PR.
  • Performance comparison reds are all "unstable" queries (both old and new fail the threshold), not regressions — expected, since this PR only touches an MSan-only #if and tests.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Aug 9, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 9, 2026
…iler

The merge queue run of this pull request was rejected by
`Stateless tests (amd_binary, flaky check)`: 2 of 54 runs of
`00974_query_profiler` failed with

    Code: 159. DB::Exception: Timeout exceeded (180 s) while flushing
    system log 'DB::SystemLogQueue<DB::TraceLogElement>'.

The test left the sampling profiler enabled for its own `SYSTEM FLUSH LOGS`
and `system.trace_log` verification queries. That is a runaway loop:
`symbolize` defaults to true and `TraceLogElement::appendToBlock` resolves
every frame of every sample through DWARF inside the flush, which costs about
1 ms per row in CI, so every sample those queries take of themselves is
another row the next flush has to symbolize, which makes the flush slower,
which lets the flush query collect even more samples of itself.
`tests/config/config.d/trace_log_no_symbolize.xml` already describes this
failure mode, but it is installed only for sanitizer builds, and the flaky
check that rejected the merge ran on `amd_binary`.

In the report below the two verification queries and the two
`SYSTEM FLUSH LOGS` queries were the four heaviest sampled queries of the
whole job: one verification query ran for 81 seconds and collected 243778
samples of itself, one `SYSTEM FLUSH LOGS` collected 96283, and together they
accounted for 561732 of the 691265 query-attributed samples (81%), while the
queries actually under test contributed about 27000 each. Over the job the
flush thread had to symbolize 1163416 rows at about 1.2 ms each - more
wall-clock time than the job lasted - so the backlog only ever grew, and a
single flush reached 369503 entries.

Switch the profiler off right after each query under test, next to the
existing `SET log_queries = 0`, so the flush and verification queries run
unprofiled. The reset before the CPU time sub-test becomes redundant and is
removed. Nothing about what the test asserts changes.

Verified against a local non-sanitizer server (`symbolize` on, serverwide
profiler at 1 second, `system.trace_log` pre-grown to 520960 rows) with the
`sleep_in_logs_flush` failpoint enabled to make the flush as slow as it is in
CI: samples collected by the flush and verification queries drop from 33341
to 149 (224x), samples of the queries under test are unchanged (1663 vs
1639), and the output still matches the reference in both cases.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=gh-readonly-queue/master/pr-113107-6cde32de1a2463c37780b7c5f9f2cc1417b2809c&sha=73f6bf32f8c91a845e16e7c4997791911be07d3a&name_0=MergeQueueCI&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29
Pull request: #113107

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov and others added 2 commits August 28, 2026 00:53
…on MSan

The flaky check runs dozens of concurrent copies of 00974_query_profiler
against one server, so everything the test asserts on goes over a single
shared lossy channel (the trace pipe, one SystemLogQueue, one flush thread
with a 180 second waitFlush deadline). Under that saturation either all
samples of a sub-test are legitimately dropped (the trace_log oracles read
0 - Stateless tests (amd_asan_ubsan, flaky check)) or the final SYSTEM
FLUSH LOGS times out (Timeout exceeded (180 s) while flushing system log
'DB::SystemLogQueue<DB::TraceLogElement>' - Stateless tests (amd_binary,
flaky check)), even after the sample budget was cut to ~600 rows per run.
Tag it no-flaky-check, like 04411_memory_profiler_sample_probability_sql_settings.

Also address the AI review: drop the no-msan tags from
02497_trace_events_stress_long and
03532_crash_in_aggregation_because_of_lost_exception. Under Memory
Sanitizer the query_profiler_* settings are silently ignored
(ThreadStatus::initQueryProfiler is compiled out), while trace_profile_events
and the memory profiler stay fully supported, so both tests keep their
coverage there.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=1b3ecc6ce3f361b240c6592541820f74c5b223c1&name_0=PR
PR: #113107

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 74837efd9fe1 (test fixes 8aab66300654 + a clean master merge).

CI on 1b3ecc6ce3f3 (report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=1b3ecc6ce3f361b240c6592541820f74c5b223c1&name_0=PR):

  • 00974_query_profiler failed in both flaky checks again, in two ways that are both artifacts of the flaky check running dozens of copies of this test concurrently against one server: on amd_asan_ubsan whole sub-tests' samples were dropped by the saturated shared trace pipeline (the trace_log oracles read 0 while the loss-proof counter oracles passed), and on amd_binary the final SYSTEM FLUSH LOGS hit the 180 s waitFlush deadline 4 times because forced flushes from all copies serialize on the one flush thread. This persisted even after the sample budget was cut to ~600 rows per run. Every oracle that the review (correctly) required needs samples to survive a deliberately lossy channel, and no budget can hold when N copies of the test are the load, so the test is now tagged no-flaky-check (same as 04411_memory_profiler_sample_probability_sql_settings). Normal stateless runs, where one copy runs among diverse tests, keep the full test on every build except MSan.
  • Addressed both AI review comments: removed the no-msan tags from 02497_trace_events_stress_long and 03532_crash_in_aggregation_because_of_lost_exception - under Memory Sanitizer the query_profiler_* settings are silently ignored while trace_profile_events and the memory profiler stay supported, so both tests keep their coverage there (replied on the threads).
  • Unrelated reds on that run: Build (arm_tsan) and the dependent Stress test (arm_tsan) = the runner failed to download the actions/checkout action (DNS error for internal-api.service.iad.github.net, infra); Docker keeper image = buildkit failure resolving buildkit-syft-scanner for the arm64 distroless image (infra); Keeper Stress Tests (PR) = health_precheck: no leader in a no-fault scenario - environment flakiness, and this PR's Keeper-side changes are MSan-gated only, so a release-build Keeper is unaffected. All of these get a fresh run on this push.

…san`

Both set `query_profiler_real_time_period_ns` / `query_profiler_cpu_time_period_ns`
to a non-zero value, which this branch now rejects with `NOT_IMPLEMENTED` under
MemorySanitizer.

`02497_trace_events_stress_long` failed outright: the setting is passed in the
`SETTINGS` clause of the query it runs in a loop, so every iteration errors out.
It is the only remaining red test on the pull request, in
`Stateless tests (amd_msan, WasmEdge, sequential, 1/2)` and in
`Stateless tests (amd_msan, flaky check)` (5/5 reruns).
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=74837efd9fe147cc4d6bde050091ca9bc0fb01b6&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20sequential%2C%201%2F2%29

`03532_crash_in_aggregation_because_of_lost_exception` did not fail, because it
sends its queries with `curl` and discards both streams, but it silently stopped
exercising anything: all 20 requests now fail on the rejected setting instead of
reproducing the lost exception. It is better skipped than vacuously green.

Co-Authored-By: Claude Fable 5 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

The test failed in `Stateless tests (amd_binary, flaky check)` with
`Timeout exceeded (180 s) while flushing system log 'DB::SystemLogQueue<DB::TraceLogElement>'`
(`TIMEOUT_EXCEEDED`) printed by the client that runs `SYSTEM FLUSH LOGS trace_log` in a loop.

The test deliberately floods `system.trace_log`: four threads run queries with a 10 ms
real-time and CPU profiler period, `trace_profile_events`, and a memory profiler sample
probability of 0.9, while a fifth thread forces a flush in a tight loop. The flaky check
repeats it back to back a few dozen times on one server, so the flush thread - which
symbolizes every row on a non-sanitizer build - falls behind and one flush exceeds the
180 s `waitFlush` deadline. Because the harness fails the test on any client stderr,
that single message is enough.

It only enters the flaky check at all because this branch adds a `no-msan` tag to it,
and it is stable in ordinary runs where a single copy runs among diverse tests. Same
treatment as `00974_query_profiler` in this branch and
`04411_memory_profiler_sample_probability_sql_settings`.
Address the AI review verdict: both tests were tagged `no-msan` because this branch
rejects a non-zero `query_profiler_real_time_period_ns` / `query_profiler_cpu_time_period_ns`
with `NOT_IMPLEMENTED` under `MemorySanitizer`, so under MSan `02497` failed on every
iteration and `02497`'s and `03532`'s requests stopped testing anything. But the sampler
is not what either test is about, so instead of skipping them, only those two settings
are now dropped in a MemorySanitizer build, detected through `system.build_options`.

`02497_trace_events_stress_long` keeps stressing `trace_profile_events` and the memory
profiler, which feed `TraceCollector` from ordinary code and remain supported under MSan.
`03532_crash_in_aggregation_because_of_lost_exception` keeps its reproducer, which is
driven by `memory_tracker_fault_probability` and `throwIf`; its `query_profiler_*` entries
are incidental leftovers of a fuzzed settings list.

Verified locally against a server built from this branch: with the settings present, both
tests pass and match their reference; with the MemorySanitizer branch forced, `02497` runs
451 queries that all reach `QueryFinish`, and `03532`'s requests run with the memory tracker
fault injected as intended, with no `NOT_IMPLEMENTED` and no syntax error from the removal.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 66242ce6fbda (a clean master merge plus two test fixes).

CI on 042214fb020b (report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=042214fb020b7f3cebd78bd022d2d6cccd341c2b&name_0=PR) had three reds:

  • AI Review ⚠️ Request changes and Stateless tests (amd_msan, ...): both Majors are implemented rather than argued. The no-msan tags on 02497_trace_events_stress_long and 03532_crash_in_aggregation_because_of_lost_exception are removed again, and instead only the two query_profiler_real_time_period_ns / query_profiler_cpu_time_period_ns settings are dropped in a MemorySanitizer build (detected through system.build_options), since this branch rejects a non-zero value there with NOT_IMPLEMENTED. 02497 keeps stressing trace_profile_events and the memory profiler on MSan, and 03532 keeps its reproducer, which is driven by memory_tracker_fault_probability and throwIf - its profiler settings really were incidental leftovers of a fuzzed settings list. Verified against a server built from this branch: unchanged paths pass and match their references; with the MemorySanitizer branch forced, 02497 runs 451 queries that all reach QueryFinish and 03532 runs with the memory tracker fault injected, with no NOT_IMPLEMENTED and no syntax error from the removal.
  • Stateless tests (amd_binary, flaky check): 02497_trace_events_stress_long failed with Timeout exceeded (180 s) while flushing system log 'DB::SystemLogQueue<DB::TraceLogElement>'. The test floods system.trace_log on purpose while a thread forces SYSTEM FLUSH LOGS trace_log in a tight loop; repeated back to back a few dozen times by the flaky check on one server, the flush thread - which symbolizes every row on a non-sanitizer build - falls behind, and because the harness fails a test on any client stderr, one such message is enough. It enters the flaky check only because this branch touches its tags, and it is stable in ordinary runs, so it is now tagged no-flaky-check, like 00974_query_profiler in this branch and 04411_memory_profiler_sample_probability_sql_settings.
  • Stress test (arm_release): Logical error: Not-ready Set is passed as the second argument for function 'globalIn' from the AST fuzzer, in VirtualColumnUtils::filterByPathOrFile. Unrelated and fleet-wide - the same signature appears on master and dozens of unrelated pull requests every day in the CI database - and tracked in Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-41a5) #107619 and Not-ready Set for globalIn on the correlated-subquery-to-join rewrite path (correlated_subqueries_use_in_memory_buffer = false) #116343. This push merges master, which now contains Report cancellation instead of leaving an in-place set unbuilt #115083, so the next run also tells whether that fix covers this variant.
  • Integration tests (amd_asan_ubsan, flaky): not a test failure. All repetitions of the changed tests passed, including test_socket_timeout; then, at 11:40:42, all three workers hung inside docker compose ... stop while tearing a cluster down and never returned, so the session timeout fired at 13:03 and the job's own docker cleanup then hung for another two and a half hours until the 18000 s job deadline. The previous commit ran the identical set of tests in 6281 s and was green.

@groeneai, could you take a look at that last one: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=042214fb020b7f3cebd78bd022d2d6cccd341c2b&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29 - a Docker-in-Docker freeze in docker compose stop that also blocks the post-job cleanup. I could not find an open issue for it; if one exists or a fix is in progress, please link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

No open issue exists for this. I searched open and closed issues for docker compose stop, docker-in-docker, stop_grace_period and dockerd hang; the nearest hit, closed #102442, is a YAML folding bug in the Iceberg compose files and is unrelated.

The fix is merged rather than in progress: #112984, 2026-08-29T13:24:30Z. The tree you link, 042214fb020b, is 764 commits behind that merge and does not contain it; your head 66242ce6fbda does, through the master merge at 06:12Z. This check has not re-run on it yet. Over 14 days the check has 58 error runs out of 2549 before that merge (2.28%) and 0 out of 125 since; about 2.9 were expected at the pre-fix rate, so that is encouraging but not conclusive.

First a correction I owe you. On #116591 I said sustained memory stall was the one thing separating these hangs from healthy nodes. That comparison was confounded by load, and I withdraw it. Your own previous commit here, 74837efd9fe1, ran the same tests to completion in 6281 s and its node carries ram-pressure at 99.7% peak RAM with memory stalled 68% of runtime, above the 60% on the failing run. 15 of the 16 other green runs of this check I sampled lasted 37 to 442 s at 4 to 35% peak RAM, which is why the band looked clean. Running hot is normal for a loaded run here, so you are right that this is not runner memory pressure.

What the artifacts do show is the inner dockerd ceasing to be scheduled. 12 containers get SIGTERM at 11:40:50, which is the compose stop you saw at 11:40:42. docker-in-docker.log then has exactly one gap over 2 minutes in 7002 timestamped lines:

11:41:45  last line before the gap
13:52:03  Container failed to exit within 10m0s of signal 15 - using the force   (12 of these, one burst)

690 lines follow the gap, so this is not a truncated upload. Those timers were due at 11:50:50, so the daemon overshot its own deadline by 121 minutes; that is dockerd's own account of the stall, so it needs no external control. compose stop is not waiting on a container that refuses to die, it is waiting on a daemon that is not running. The 10 minutes is deliberate, from stop_grace_period: 10m in tests/integration/helpers/cluster.py, whose shutdown passes no --timeout and relies on it. This also covers the cleanup you noticed: nothing is logged between 13:58:48 and 16:32:48, and once the 18000 s backstop fired, docker rm -f finished in 19 s. #113589's red looks identical, its dind log stopping at 02:12:31 against a 07:07:17 job end, though that file ends there so truncation is not excluded on that one.

Cheap discriminator for the next occurrence: compare the last timestamp in docker-in-docker.log with the job end time.

The outer inactivity bound I offered on #116591 is still waiting on your call. It would have cut these runs short rather than prevented them. If this class appears on a tree that already carries #112984, that is the recurrence you asked me to fix and I will take it.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed e2799101185b — a clean merge of master (946 commits, no conflicts). QueryProfiler.cpp.o, Settings.cpp.o, ServerSettings.cpp.o, CoordinationSettings.cpp.o and Server.cpp.o all compile after the merge.

CI on 66242ce6fbda was green except a single job-level red, and it is not a test failure of this pull request:

  • Integration tests (amd_asan_ubsan, flaky) — report: every test in the job passed, including this pull request's own test_distributed_ddl/test.py::test_socket_timeout in both the configs and configs_secure parametrizations, plus test_keeper_profiler and test_trace_collector_serverwide. The job was failed only by the Container memory budget exceeded (/docker) guard. This is fleet-wide infrastructure, not this branch: 576 occurrences across 261 pull requests on 2026-08-31 and 172 across 139 on 2026-09-01, per CIDB.

AI Review on 66242ce6fbda is ✅ Approve with no inline findings, there are no unresolved review threads, and alexey-milovidov's LGTM stands.

@groeneai, the Container memory budget exceeded (/docker) guard is failing integration jobs fleet-wide since 2026-08-31 (see the CIDB counts above): https://github.com/ClickHouse/ClickHouse/actions/runs/33296819525/job/99262785281 — please investigate and provide a fix in a separate pull request. #115785 (size integration test workers from the job cgroup limit instead of host RAM) looks like it may already cover this; if so, please confirm and link it here. I found no open issue tracking this guard by name.

# profiler, both of which feed `TraceCollector` from ordinary code - stays supported there, so drop
# only these two settings on that build instead of skipping the test.
QUERY_PROFILER_SETTINGS="query_profiler_real_time_period_ns = 10000000, query_profiler_cpu_time_period_ns = 10000000,"
if [ "$($CLICKHOUSE_LOCAL -q "SELECT value LIKE '%-fsanitize=memory%' FROM system.build_options WHERE name = 'CXX_FLAGS'")" = "1" ]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This keeps the supported trace_profile_events / memory-profiler coverage on MemorySanitizer, but I still do not see a focused regression test for the new user-visible contract in SettingsImpl::set: a positive query_profiler_* period should now fail with NOT_IMPLEMENTED on MSan instead of being silently ignored.

As written, the updated MSan-covered stateless cases (02497, 03532) now route around that path by stripping the settings, and the profiler-specific tests are tagged no-msan. If the guard in src/Core/Settings.cpp regresses later, CI will likely stay green while the silent no-op surface comes back.

Please add the smallest build-conditional stateless check that sends a positive query_profiler_real_time_period_ns / query_profiler_cpu_time_period_ns (plain SET or per-query SETTINGS) and expects NOT_IMPLEMENTED on MSan.

try:
cluster.start()

if node1.is_built_with_memory_sanitizer():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixture now starts from global_profiler_* = 0 and skips on MemorySanitizer before proving the new ServerSettingsImpl::set contract: a positive global profiler period should fail with NOT_IMPLEMENTED on MSan instead of being accepted and silently doing nothing.

With tests/config/install.sh also dropping serverwide_trace_collector.xml on MSan, I do not see anything left that would fail if the guard in src/Core/ServerSettings.cpp regressed later. The integration suites would keep starting from zero and the old silent no-op surface would return unnoticed.

Please add the smallest focused check here (or an equivalent config-load test) that a non-zero global_profiler_real_time_period_ns / global_profiler_cpu_time_period_ns is rejected on MSan.

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Container memory budget exceeded (/docker) already has a fix, and it is yours: #117412, merged 2026-09-01T11:31:33Z as d65ba26ae8b3. #117411 was closed unmerged 20 minutes earlier in favour of it. The run you cite is on 66242ce6fbda, which predates it; the master merge you pushed at 13:56Z (e2799101185b) already carries it, so a fresh run on this head uses the raised budget.

It does not close the guard on its own. Two runs whose tree carries #117412 still tripped it. Fix presence read from each job's own environment (CI_DIND_INIT_RESERVE=8589934592, CI_DIND_NESTED_BUDGET=52372127744, the raised 48.78 GiB cap):

job /docker peak OOM kills in /docker
#110552, 12:45:22Z 48.78 GiB of 48.78 GiB cap 7 (3 clickhouse, 4 gdb)
#117490, 12:33:22Z 48.78 GiB of 48.78 GiB cap 4

Both finished 1253 passed, 23 skipped and were failed only by the guard, the same shape you describe. The other six occurrences after 12:00 today are still on 40.78 GiB trees, and the four master runs of that shard on trees carrying the fix (762e8e55, 9da5fe39) are green so far, so what is left is a smaller residual rather than the rate you counted.

The budget cannot regulate itself on this carrier. The runner reports ncpu: 16, so cpus // MAX_CPUS_PER_WORKER is 3 and that is what binds: mem_limit_gb // MAX_MEM_PER_WORKER is 3 at the old 40 GiB budget and 4 at the new 48 GiB one, so the plan is 3 workers either way. Three workers modeled at MAX_MEM_PER_WORKER = 11 is 33 GiB, against a measured charge to /docker of at least 48.78 GiB.

On #115785: it does not cover this, and it is still a draft last touched 2026-08-26. What it proposes, sizing workers from the enforced limit instead of host RAM, is already on master in a tighter form. nested_budget_gb in ci/jobs/integration_test_job.py derives the budget from CI_DIND_NESTED_BUDGET, the cap on the /docker leaf itself, which is why both jobs above print mem_gb: 48 rather than 61 (host RAM) or 59 (the job cgroup limit). #115785 reads the job cgroup limit, the looser of the two, and on this carrier it changes no decision: min(3, mem_gb // 11) is 3 at 48, 59 and 61, and min(3, mem_gb // 20) is 2 at both 48 and 59. Its diff also no longer applies, since it patches the Utils.physical_memory() line and the if args.workers: block that nested_budget_gb and planned_workers replaced.

No open issue tracks the guard by name, confirmed: repo:ClickHouse/ClickHouse is:issue is:open "Container memory budget" returns 0, and the 97 hits for the phrase are all pull requests.

I am investigating the residual on that shard and will follow up here with a separate pull request.

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Opened #117564.

It is a container leak, not capacity. test_refreshable_mat_view, test_refreshable_mat_view_replicated and test_distributed_over_distributed declare their cluster fixture scope="session". A leaf pytest file cannot share a fixture, so session scope only defers cluster.shutdown() to the end of the xdist worker's session, and their servers, Keepers, MinIO and proxies stay charged to the /docker leaf for the rest of the ~105 minute job: 12.4-15.2 GiB, 26-37% of its anonymous budget. worker_plan cannot see them, because at ncpu: 16 the CPU half binds at 3 workers and models 3 * 11 = 33 GiB at any budget, so it is a fixed tax rather than a share. Those are the only 3 of 1120 leaf test files using session scope; the PR changes the 3 words and adds a various_checks.sh check so the class cannot return.

Proof it is those two modules and not the shard's general load: over one job's 1348 containers the lifetime median is 0.7 minutes and p90 is 4.6, with 18 outliers at 93.5-106.9 minutes, all stopped inside a 12-second window at session end and matching the two session-scoped compose projects container for container. 189 compose projects ran; exactly those 2 leaked.

I am not claiming it closes the guard on its own. The shutdown gdb attach is a second contributor, resident at 70 of 154 kernel OOM snapshots at 4.8-7.7 GiB RSS; that is the #117202 mechanism and I left it alone.

@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 41 queries analysed

This PR disables the sampling query profiler in MemorySanitizer builds (QUERY_PROFILER_SUPPORTED) and rejects non-zero profiler periods there, plus related settings-validation and test-config edits. None of that touches the query-execution path exercised by a regular benchmark build, so the flagged -34.7% improvement on tpch_adapted_1_official Q17 cannot plausibly be attributed to the diff. The query's own history is noisy and the base measurements were highly variable, consistent with run-to-run variance rather than a real PR effect, so this row is downgraded to not-sure.

clickbench

🟢 No significant changes

tpch_adapted_1_official

⚠️ 1 inconclusive

Flagged queries (1 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 17 not_sure 101 66 -34.7% <0.0001 The PR only disables the sampling query profiler under MemorySanitizer and touches Keeper/server settings plumbing; the non-MSan query hot path is unchanged, so this -34.7% on a noisy query is run-to-run variance.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: e4cd12bf-cc66-42da-8cd0-f0ea9b6bf405
  • MIRAI run: 076c97d0-32fa-4d14-a4ea-cc2900d647f1
  • PR check IDs:
    • clickbench_1231729_1788556437
    • clickbench_1231735_1788556437
    • clickbench_1231741_1788556436
    • tpch_adapted_1_official_1231752_1788556437
    • tpch_adapted_1_official_1231763_1788556437
    • tpch_adapted_1_official_1231799_1788556437

@clickhouse-gh clickhouse-gh Bot added the comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). label Sep 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 5, 2026
Merged via the queue into master with commit 29b7f01 Sep 5, 2026
175 checks passed
@alexey-milovidov
alexey-milovidov deleted the msan-disable-query-profiler branch September 5, 2026 21:01
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 5, 2026
pull Bot pushed a commit to Spencerx/ClickHouse that referenced this pull request Sep 9, 2026
The validation loop swaps in the master-HEAD binary for each remaining build
type without reinstalling the config tree, which was installed for
`build_types[0]`, always `*_asan_ubsan`. Since ClickHouse#113107 an msan server rejects a
non-zero `global_profiler_real_time_period_ns` while parsing its own settings,
so the tree's leftover `serverwide_trace_collector.xml` aborts startup with
`Code: 48 NOT_IMPLEMENTED` on the `*_msan` swap. That turns both
`Bugfix validation (functional tests, amd64|aarch64)` legs red, and because the
loop breaks there, `*_msan` and `*_debug` can no longer supply a reproduction
for a labelled bug-fix PR whose test does not reproduce on `*_asan_ubsan`.

The `*_debug` swap has the mirror problem: `trace_log_no_symbolize.xml`, linked
for the sanitizer binary, stays behind and silently leaves in-flush
symbolization off, unlike the ordinary `Stateless tests (debug)` job. It was
unreachable so far only because the loop breaks at `*_msan` first.

Call `install_build_type_configs` after the swap, beside the existing
`set_memory_ratio`/`reset_memory_ratio` re-derivation, which is there for the
same reason: the config tree outlives the binary it was installed for.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants