Repository navigation
Conversation
…h STREAM ReadFromMergeTree::initializePipeline strips data parts from the storage snapshot by mutating storage_snapshot->data in place. ReadFromMergeTree::clone() copies the storage_snapshot shared pointer, so the original lookup plan and every clone share one StorageSnapshot. A direct JOIN rebuilds its lookup pipeline for each probe block (and the STREAM source rebuilds its sub-pipeline repeatedly), so one build replaced and destroyed a SnapshotData whose mutations_snapshot was still read by an overlapping build, which MSan reports as use-of-uninitialized-value. Rebind this step's snapshot to a private clone instead of mutating the shared one. Found by the AST fuzzer under MSan on PR ClickHouse#111492 (unrelated to that PR). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-0:20260723-115200 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-0:20260723-115200 |
|
cc @novikd @antaljanosbenjamin - could you review this? It fixes an MSan use-of-uninitialized-value in a |
|
Workflow [PR], commit [6574412] Summary: ❌
AI ReviewSummaryThis PR fixes a real lifetime issue in Tests
Final Verdict
|
…anging The regression test added in the previous commit was flaky and could hang CI: it used only two left parts and killed the client without stopping the server-side STREAM query, so the use-of-uninitialized-value reproduced on only about half of the runs, and the streaming queries that outlived their clients held the table locks. That made the flaky check fail intermittently and left the query running at the end of the run, so the final DROP timed out and the end-of-run hung check reported hung queries. Bugfix Validation (which runs the new test once per arch on master HEAD, including under MSan) also often failed to reproduce the crash and reported the test as not validating the fix. Rework the test to trigger the bug on every run and to leave nothing running: seven probe keys (only key 1 matches), each in its own part, so with max_block_size=1 many direct-join lookup pipelines are rebuilt over the shared StorageSnapshot and overlap. Repeat the streaming query 25 times, each under a one-second client timeout (the bug is hit while the lookup pipeline is built, so a short window per query is enough). After the loop, KILL any streaming query that outlived its client and wait for it to leave system.processes before dropping the tables, so the DROP cannot hang and the end-of-run hung check stays clean. Assert that the exact STREAM query plans through the direct join and that the non-STREAM form of it runs and fills the ALTER-added column, so the test fails loudly if it stops exercising the fixed path. Also tidy the code comment added by the fix. Verified under MSan: the pre-fix server aborts on every run and the fixed server passes with no hang. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…d server The test is run against master HEAD by Bugfix validation, where the use-of-uninitialized-value is present and the STREAM direct-join corrupts the server. The unbounded KILL QUERY ... SYNC and processlist drain then blocked forever against the dead server, hanging the amd64 Bugfix validation job to the 18000s run timeout instead of failing cleanly. Hard-bound and make best-effort the liveness check, KILL QUERY, drain and DROP steps. On a healthy server every bound is a no-op and SYNC still confirms the streaming queries are gone before the DROPs, so the fix path and the flaky check are unchanged; on the pre-fix binary the test now terminates in seconds while still reproducing the bug. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…died
The previous revision bounded every cleanup step with `timeout ... || true`
unconditionally, so on a live server a genuine failure (KILL SYNC not
completing, the process list never draining, or a DROP blocked on a leaked
STREAM query) was swallowed and the test still printed "alive" and passed.
That weakened the regression contract and could leak the query/table-lock
state the test is meant to clean up.
Gate cleanup strictness on a liveness probe, mirroring clickhouse-test's own
_cleanup_database ("best-effort only when the server is actually dead"): if
the server is up, KILL/drain/DROP must genuinely complete or the test prints
"cleanup incomplete" and fails; only a confirmed-dead server (the pre-fix
binary aborting under MSan during Bugfix validation) skips cleanup and fails
fast via the missing "alive". Every step stays time-bounded, so even a wedged
live server fails in seconds instead of hanging the job to its timeout.
The source fix and the STREAM loop that reproduces the use-of-uninitialized
value are unchanged.
… timeout The live-server cleanup path set a flag on a timed-out step but kept running the remaining drain loop and both DROPs, so a wedged-but-live server could still burn up to 60 + 60*(5+0.5) + 60 + 60 = 510s before printing "cleanup incomplete". That is the exact case this revision was meant to bound. Move the KILL/drain/DROP steps into a helper that returns non-zero on the first bounded step that times out, so the outcome (already doomed to "cleanup incomplete") is printed immediately and the rest is skipped. The healthy path is unchanged: every step passes quickly and prints "alive". Co-Authored-By: Claude Opus 4.8 <[email protected]>
The regression loop launched each direct-join STREAM query under timeout 1 and tore it down after one wall-second. On a slow server the client can time out during handshake or planning, before the query enters ReadFromMergeTree::initializePipeline (the path this PR fixes), so the test could go green without ever exercising the bug. Now each STREAM query runs in the background and is only killed after it registers in system.processes, which proves it reached execution. The dead-server and wedged-server failure paths are unchanged and still bounded. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ive server The wait-for-registration loop exited on three conditions: probe error, the query registering, or the 30s window expiring. In the last case the query was never observed in system.processes, yet the iteration still tore the client down and, on a live server, counted as success. On a slow server that could let the test reach "alive" without any iteration provably entering ReadFromMergeTree::initializePipeline, the path this PR fixes. Track whether the query registered and, on a live server where it did not within the window, print a distinct line and stop so the diff against the reference fails the test instead of a silent pass. Test-only change; the source fix is unchanged.
The wait loop that guards the KILL/tear-down previously exited as soon as the
STREAM query was visible in system.processes. That is not proof it reached the
fixed ReadFromMergeTree::initializePipeline path: ProcessList::insert makes a
query visible before the executor is attached (see
04410_primes_source_cancellation.sh), so an iteration could register and be
killed before the streaming read ever ran, and the test could pass without
exercising the fix.
Gate on an execution-side signal instead: wait for read_rows>0 in
system.processes (the pattern used by 04039_merge_tree_snapshot_teardown_race.sh)
before killing the query, and fail the iteration ("stream query did not start")
if no row is read within the window on a live server. read_rows>0 means the
executor is attached and the MergeTree read is producing rows.
Test-only change; the C++ fix is unchanged.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
| reached=0 | ||
| q_start=$EPOCHSECONDS | ||
| while (( EPOCHSECONDS - q_start <= 30 )); do | ||
| rr=$(timeout 5 $CLICKHOUSE_CLIENT -q "SELECT max(read_rows) FROM system.processes WHERE query_id = '$qid'" 2>/dev/null) || break |
There was a problem hiding this comment.
read_rows here is still query-global progress, not a right-side lookup signal. system.processes / query_log define it as rows read by the whole query, and JoiningTransform::readExecute only calls join->joinBlock after the left probe block has already been materialized. That leaves a live-server window where t_djs_left has bumped read_rows, this loop sets reached=1, and the test kills the query before DirectKeyValueJoin::joinBlock / storage->getByKeys ever rebuild the right-side lookup plan. In that case the iteration still counts as success without touching the fixed ReadFromMergeTree.
Please wait on a lookup-specific signal instead. One workable option is to make the first probe block deterministically match and gate on ProfileEvents['JoinBuildTableRowCount'] > 0 in system.processes; another is any other counter tied specifically to the direct-join lookup build path.
There was a problem hiding this comment.
The pre-fix binary aborts the server while running this exact test: the post-loop liveness probe then prints "server died", which mismatches the "alive" reference and fails the test. A binary cannot abort on a code path it never executes, so the differential (fails on the pre-fix binary, passes on HEAD) is itself proof the loop drives execution into ReadFromMergeTree::initializePipeline; read_rows > 0 only ensures each iteration runs far enough to matter before the KILL.
I already tried gating on JoinBuildTableRowCount > 0 and it is flaky for this fixture: only key 1 of the seven probe keys matches the single right row, so for the other six lookups the counter stays 0, and it does not reliably surface as >0 in system.processes before the query is killed. On a healthy live server that gate false-fails with "stream query did not start". Making the first block deterministically match does not remove that lag, because the counter is observed asynchronously through system.processes. A flaky gate is worse than the current one, which passes the amd_msan / amd_debug / amd_tsan flaky checks on this head.
Keeping the read_rows > 0 gate. Leaving the rest of this test-shape discussion for human review.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 2/2 (100.00%) · Uncovered code |
CI finish ledger — 6574412Every failure below has an owner. The new regression test
Session id: cron:our-pr-ci-monitor:20260725-113000 |
|
cc @Michicosun |
|
This is no longer needed |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improves the stability of experimental
STREAMqueries that use adirectjoin against aMergeTreetable afterALTER TABLE ... ADD COLUMN.Description
Found by the AST fuzzer under MSan on PR #111492 (unrelated to that PR's changes). The MSan report itself lost its stack (nested error while writing), so the crashing query was recovered from the fuzzer log:
with
join_algorithm = 'direct',enable_analyzer = 1,enable_streaming_queries = 1, wherer.new_colwas added byALTER TABLE t_right ADD COLUMN new_col String DEFAULT 'default_value'.Root cause:
ReadFromMergeTree::initializePipelinestrips data parts from the storage snapshot (for theenable_remove_parts_from_snapshot_optimization/ streaming path) by mutatingstorage_snapshot->datain place.ReadFromMergeTree::clone()copies thestorage_snapshotshared pointer, so the original lookup plan and every clone share oneStorageSnapshot. AdirectJOIN rebuilds its lookup pipeline for each probe block (and theSTREAMsource rebuilds its sub-pipeline repeatedly), so one pipeline build replaced and destroyed aSnapshotDatawhosemutations_snapshotwas still read by an overlapping build, giving MSan a use-of-uninitialized-value.Fix: rebind this step's own
storage_snapshotto a private clone viaStorageSnapshot::clone(...)instead of mutating the shared snapshot in place. The clone keeps the same storage and metadata, only the strippedDatais private, so no build observes another build's destroyedSnapshotData.CI report (MSan,
AST fuzzer (amd_msan)): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111492&sha=1f9f9e0c14bca355fd9cf558efcb722aca37f1b9&name_0=PR&name_1=AST%20fuzzer%20%28amd_msan%29Reproduced locally on an MSan build (crash rate about 1 in 8 runs); with the fix it no longer reproduces (0 crashes over many runs) and results are unchanged for plain,
LowCardinality, andNullableadded columns. Added a regression test that spawns the streaming direct-join query repeatedly and asserts the server stays alive.