Repository navigation
Make flaky test 03568_udf_memory_tracking lighter to avoid TSan timeout - #107699
Algunenano merged 2 commits into
Conversation
|
Pre-PR validation gate
Session: cron:clickhouse-worker-slot-4:20260617-035100 |
|
cc @rschu1ze — could you review this? Test-only: tags |
| @@ -1,3 +1,6 @@ | |||
| -- Tags: no-parallel | |||
There was a problem hiding this comment.
Using no-parallel should be the last resort, and ideally reserved for tests that modify the process global state (drop cache for example). Can't you instead make the test smaller / less resource intensive while still testing the memory tracking of UDFs?
There was a problem hiding this comment.
Good point, dropped no-parallel. Instead I made the test lighter: 300 blocks (numbers(100)+numbers(200)) -> 100 blocks (numbers(40)+numbers(60)), 3x fewer fork/exec. That alone clears the TSan timeout (the cost is per-block fork of /bin/sh -c awk).
The drift the test catches is ~1MB/block (one TimeoutWriteBufferFromFileDescriptor freed off the query thread group), so a smaller block count still exceeds the 20MB assertion without the fix. Measured pre-fix vs current binary:
| blocks | without fix | with fix |
|---|---|---|
| 40 | 46.6 MB | 5.4 MB |
| 60 | 67.8 MB | 5.4 MB |
So it still FAILS on a regression (clickhouse-test on a pre-fix binary: min/max_less_then_20mb: 0) and passes 20/20 with randomization in the parallel bucket. Assertions and the UDF are unchanged.
|
Workflow [PR], commit [e01d582] Summary: ✅ AI ReviewSummaryThis PR reduces Final VerdictStatus: ✅ Approve |
The test streamed 300 single-row blocks (numbers(100) + numbers(200) with max_block_size = 1) through an executable UDF. Each block forks /bin/sh -c awk, which under TSan is roughly two orders of magnitude slower than a debug build. On the parallel test bucket the CPU contention pushed total run time past the 600s per-test timeout (CIDB: OK runs p50 247s / p90 303s / max 506s, plus 5 clean 600s timeouts over 40 days), making the test flaky on Stateless tests (amd_tsan, s3 storage, parallel). Reduce the workload to 40 + 60 = 100 blocks (3x fewer fork/exec) so it runs well inside the timeout while still exercising the per-block memory tracking that fb79ace fixed. The fix is the thread-group attachment of the data-sending threads, so query memory_usage stays flat regardless of block count; without it, each block leaks ~1MB into the query tracker (one TimeoutWriteBufferFromFileDescriptor, DBMS_DEFAULT_BUFFER_SIZE) freed off the query thread group. Measured locally: blocks without fix with fix 40 46.6 MB 5.4 MB 60 67.8 MB 5.4 MB So 40 and 60 blocks both stay 2.3x-3.4x above the 20MB assertion without the fix (test still fails on a regression) and ~3.7x below it with the fix. The two assertions and the executable UDF are unchanged. Dropping no-parallel: the smaller workload no longer needs it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
dcad003 to
e0243f7
Compare
Pre-PR validation gate (updated for the lighter-test approach)
Session id: cron:clickhouse-worker-slot-6:20260617-095600 |
|
@groeneai It seems it still takes almost 4 minutes, which is why the flaky check fails https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107699&sha=e0243f79290ce4a43eb2392d40cd9fbdfcdcd918&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29. Make it even faster |
The reduced 100-block workload still runs over the flaky-check 180s soft-check (TEST_MAX_RUN_TIME_IN_SECONDS) under amd_tsan, where each per-block fork/exec of the executable UDF is ~100x slower than debug. clickhouse-test marks such a run FAIL/TOO_LONG unless the test carries the long tag (tests/clickhouse-test gate: test_runs>1 and flaky_check and total_time>180 and "long" not in tags). The long tag exempts that soft-check and cuts the flaky-check repeat count to the long ratio (~10%), which also reduces self-contention. It does NOT make the test sequential (only no-parallel/sequential do), so the test keeps running in the parallel bucket. The 100-block workload and both < 20MB assertions are unchanged, so it still catches a memory-tracking regression on every build including TSan. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Follow-up: after the 300->100 block reduction, CI surfaced a separate failure on That soft-check (tests/clickhouse-test: |
Pre-PR validation gate (updated for the
|
| # | Question | Answer |
|---|---|---|
| a | Deterministic repro? | Yes. The gate is deterministic: tests/clickhouse-test fails a test when test_runs>1 and flaky_check and total_time>180 and "long" not in tags. The 100-block fork/exec workload still exceeds the 180s soft-check under amd_tsan (each per-block /bin/sh -c awk is far slower than debug; the flaky-check repeats the test many times). |
| b | Root cause explained? | The 600s regular-timeout flake was fixed by the 300->100 reduction, but the flaky-check job has a SEPARATE 180s per-run soft-check (TEST_MAX_RUN_TIME_IN_SECONDS) that is only bypassed by the long tag. The test is correct but legitimately heavy under TSan, so it crosses 180s in flaky-check mode. |
| c | Fix matches root cause? | Yes. -- Tags: long is exactly what gates that soft-check (line ... and "long" not in tags), and it also cuts the flaky-check repeat count to the long ratio (~10%), reducing self-contention. It is additive to the approved block reduction. |
| d | Test intent preserved / new tests added? | Preserved. long does NOT serialize the test (only no-parallel/sequential do), so it keeps running in the parallel bucket. Workload and both < 20MB assertions are byte-for-byte unchanged. |
| e | Both directions demonstrated? | Yes. Replicating the gate logic: without long, total_time>180 in flaky-check -> FAIL=True; with long -> FAIL=False (even at 500s). End-to-end clickhouse-test with the fix: [ OK ], "Found 1 parallel tests and 0 sequential tests". Tag parser confirms is_long_test=True, is_sequential=False. |
| f | Fix is general, not a narrow patch? | N/A (test-only change; no source modified). long is the idiomatic tag for tests that are correct but legitimately heavy under sanitizers. |
Session id: cron:clickhouse-worker-slot-4:20260617-115700
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 306 line(s), 6 function(s) across 107 file(s) · Details Top files
|
03568_udf_memory_tracking fails sporadically on Stateless tests (amd_msan, WasmEdge, parallel, 2/2) with exit code 242 (UDF_EXECUTION_FAILED) wrapping "Code: 159 Pipe read timeout exceeded 10000 milliseconds". This is not a test timeout: the failing runs die in 13.7 s / 16.3 s / 27.3 s against the 600 s per-test limit. It is a per-invocation bound. test_function is declared with execute_direct=0 and no command_read_timeout, so ExternalUserDefinedExecutableFunctionsLoader.cpp:234 gives it the 10000 ms default. execute_direct=0 means every call vfork+execs /bin/sh -c "awk ...", and test_function is not an executable_pool, so a fresh pipe and process are created per call. The test uses max_block_size = 1 over numbers(40) and numbers(60), i.e. 100 independent fork/exec round-trips; that per-block shape is the coverage the test exists for. The read clock is armed independently of the writer's progress: ShellCommandSource spawns each SendDataTask on a separate thread and builds the input format over timeout_command_out immediately, so the 10 s budget covers vfork, exec, sh and awk startup plus the scheduling delay of our own writer thread. Under MSan in a loaded parallel bucket one round-trip can exceed it, and one slow read out of 100 fails the whole query. The two distinct throw sites across the reports (once while reading the header, twice inside ParallelParsingInputFormat) confirm a startup-window stall. PR ClickHouse#107699 cut the round-trips from 300 to 100. That lowers the number of dice rolls but leaves the per-roll ceiling untouched, which is why the failure carried over from TSan to MSan; trimming the workload again would attack the wrong term and erode coverage. Every assertion is unchanged: both memory checks, count() = 2, the 100-block workload and the reference file. Nothing is masked either: awk on one row is sub-millisecond work, all 100 round-trips take 0.43 s locally, and the bound stays finite at 60 s so a genuine hang still fails. The same knob at the same value already fixed the identical signature for executable dictionaries in ClickHouse#108933. Closes: ClickHouse#112994
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
03568_udf_memory_trackingwas flaky onStateless tests (amd_tsan, s3 storage, parallel): clean 600s per-test timeouts (CIDB: OK runs p50 247s / p90 303s / max 506s, plus 5 timeouts over 40 days). It streamed 300 single-row blocks (numbers(100)+numbers(200),max_block_size = 1) through an executable UDF; each block forks/bin/sh -c awk, which is ~100x slower under TSan, and parallel CPU contention pushed it past the timeout.Reduce the workload to
numbers(40)+numbers(60)= 100 blocks (3x fewer fork/exec) and drop the (previously proposed)no-paralleltag.The fix under test (fb79ace) attaches the data-sending threads to the query thread group, so query
memory_usagestays flat regardless of block count. Without it, each block leaks ~1MB into the query tracker. Measured locally with a pre-fix vs current binary:So both queries stay 2.3x-3.4x above the 20MB assertion without the fix (the test still fails on a regression) and ~3.7x below it with the fix. The two
< 20MBassertions and the executable UDF are unchanged.Verified via
clickhouse-test: pre-fix binary FAILS (min/max_less_then_20mb: 0), current binary passes 20/20 with randomization in the parallel bucket.Version info
26.6.1.934