Repository navigation
Fix flaky 01169_old_alter_partition_isolation_stress: orphaned client at teardown - #107883
Conversation
… at teardown
The background loops thread_insert and thread_select run an infinite
"while true" of clickhouse-client invocations and are stopped with
"kill -TERM $PID". That signal terminates only the bash subshell running
the loop, not the clickhouse-client child it has in flight. The orphaned
client is reparented, keeps running, and executes its INSERT INTO src /
SELECT after the test's final DROP TABLE (and after the runner drops the
per-test database). The late query then prints
"Table ... src does not exist" (UNKNOWN_TABLE) or
"Database ... does not exist" (UNKNOWN_DATABASE) to the shared stderr,
which the test harness reports as a "having stderror" failure even though
the test logic itself is correct. Reruns pass because the race is timing
dependent. wait_for_queries_to_finish does not help: a client still in the
connect/auth phase is not yet visible in system.processes, so the drain
returns before the orphan reaches the server.
Replace the kill-based stop with a stop flag. Each loop checks the flag
between iterations and exits cleanly after its current client has finished,
and the script then "wait"s for both loops, so no client can outlive the
teardown. The prior fixes (98280 increasing the drain timeout, 99018 making
the final wait non-fatal) worked around this same orphan/drain race without
removing its source.
Observed locally with a debug build: the kill-based version leaked the
exact CI signature ("Table ... src does not exist (UNKNOWN_TABLE)") in
2 of 12 runs; the stop-flag version leaked 0 of 20, and the full test
passes 5/5 with stdout matching the reference.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-0:20260618-144500 |
|
cc @alesapin — could you review this? Test-only fix for flaky |
|
Workflow [PR], commit [e0cf7b0] Summary: ✅ AI ReviewSummaryThis PR replaces the Findings
Final VerdictNeeds one more fix before merge: the teardown race is addressed, but the test still drops one of its own invariant failures. |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 354 line(s), 11 function(s) across 140 file(s) · Details Top files
|
CI summary — commit
|
The stop flag was raised only after `wait $PID_3 && wait $PID_4`, which is unreachable on both error paths. With errexit, a nonzero `wait $PID_3` does not abort the script because it is the left operand of `&&`; it merely skips `wait $PID_4`, so the failure is reported as success and teardown starts while thread_partition_dst_to_src may still be mutating src / dst. Measured on a harness mirroring the final region: the script exits 0 where the worker failed with 3. If instead `wait $PID_4` fails, errexit fires before `touch "$STOP_FILE"`, so thread_insert and thread_select are never asked to stop. They survive the script and keep running clickhouse-client against tables the test has dropped, which is the orphaned-client leak this test was changed to avoid. Measured with a heartbeat file: the loop keeps appending after the script has exited. Raise the flag from an EXIT trap so it happens on every path, and wait for each worker separately so the first failure is the exit status. The trap also drains the partition workers, so a worker still mid-query when another one fails finishes inside the trap rather than after teardown. The `||:` on the two loop waits is dropped: with the flag they exit cleanly, so a nonzero status is a real failure -- thread_select is the only check of transient isolation violations during the run, and the four final queries only validate the terminal state.
The comment named the old form; the reason for the change belongs in the commit message, not next to the code.
CI finish ledger - 6cd876eb88b0d1cd28c7e0b3e0fa2b48a1cd41a5No failures on this head, so there is nothing to assign an owner to.
174 of 174 check-runs completed (56 success, 118 skipped). This head is the trap-based teardown fix answering the two Session id: cron:our-pr-ci-monitor:20260729-213000 |
CI finish ledger - 6cd876eEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Every other dispatched check reported success. This supersedes the earlier ledger on this PR, Session id: cron:our-pr-ci-monitor:20260809-170000 |
|
@groeneai is this pr still relevant? |
|
Yes, still relevant: the defect is live on master and the patch applies unchanged.
CIDB, last 30 days for this test: 4 failed rows, 3 of them this signature, and one of those 3 is on master rather than on a PR.
Three different error codes, one mechanism: whichever query the orphaned client happens to be running when teardown drops the tables. The 4th row is a server-side abort in another PR's build, unrelated to this. The branch is mergeable with no conflicts, CI on |
| } | ||
| trap stop_threads EXIT | ||
|
|
||
| # One wait per worker, so the first failure becomes the exit status. |
There was a problem hiding this comment.
thread_select failures are surfaced now, but the type=3 worker still has the same false-negative shape. thread_partition_src_to_dst wraps its whole transaction in out=$(...) ||: and then only treats SERIALIZATION_ERROR as special. If its internal throwIf fires, or any other exception comes back, the function still returns success and even advances count / sum as if the transaction committed.
That means this test can still go green after it has already observed a real invariant violation on the type=3 path. Please make SERIALIZATION_ERROR the only expected retry and fail the worker on every other nonzero result, like the newer 01169_alter_partition_isolation_stress.sh does.
There was a problem hiding this comment.
Checked this against the head before answering. The mechanism is real, the consequence is not.
out=$(...) ||: does discard the worker's status, and count / sum do advance on a non-SERIALIZATION_ERROR result. What that misses is the branch right after it: grep -Fv SERIALIZATION_ERROR | grep -F "Received from " prints the offending exception, and then the src / dst dump, to stdout, and clickhouse-test fails any test whose stdout carries an exception regardless of the exit status (having exception in stdout, tests/clickhouse-test:1539, unconditional check at :3640).
Measured on a local debug server (26.10.1.1), one run per arm:
| arm | verdict | failure reason |
|---|---|---|
| head, unmodified | [ OK ] |
|
type=3 throwIf forced to fire on every iteration |
[ FAIL ] |
having exception in stdout |
type=3 throwIf forced on exactly one iteration (i=5) |
[ FAIL ] |
having exception in stdout |
type=3 client made to fail silently at i=5 (rc=1, empty output) |
[ FAIL ] |
having exception in stdout |
No failing arm reported a return code: reason, so the status really was 0 in each case and the test failed anyway. The last arm answers the count / sum half: the advance is self-detecting, because the drifted expectation makes the next iteration's own throwIf fire.
So I am leaving thread_partition_src_to_dst as it is. It is unchanged master code, this PR is +32/-6 on the teardown path, and reshaping that worker into the sibling's transactions.lib form is a separate change to a test that is currently green.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Flaky in
Stateless tests (..., parallel).thread_insertandthread_selectwere stopped withkill -TERM $PID, which kills only the bash subshell, not theclickhouse-clientin flight. The orphan is reparented and runs its query after the finalDROP TABLE, printingTable ... src does not existorDatabase ... does not existto the shared stderr, reported as "having stderror".wait_for_queries_to_finishmisses it: a client still in connect/auth is not yet insystem.processes.The loops now stop via a flag file, exiting after their current client finishes. The name uses
CLICKHOUSE_TEST_UNIQUE_NAME, so the test stays parallel-safe. #98280 and #99018 worked around this race without removing its source.Two error-path defects found during review are fixed as well:
wait $PID_3 && wait $PID_4, unreachable on either failure. Undererrexita nonzerowait $PID_3does not abort (left operand of&&), it only skipswait $PID_4, so a failed worker was reported as success and teardown began while the other was still mutatingsrc/dst. Ifwait $PID_4failed instead,errexitfired before the flag was raised and the loops ran past the end of the test. The flag now comes from anEXITtrap, and each worker is waited for separately so the first failure is the exit status.wait $PID_1 ||:discarded a real failure ofthread_insert/thread_select.thread_selectis the only check of transient isolation violations during the run, so the test could pass after it had exited on athrowIf.The orphan is timing dependent and does not reproduce on an idle host, so the evidence is a deterministic A/B rather than a rerun.
Validation and CI evidence
A harness mirroring the final region, with a heartbeat file detecting a loop that outlives the script. Old code: exits 0 on a
PID_3failure, leaves the loop running on aPID_4failure, exits 0 on athread_insertfailure. Fixed: 3, loop stopped, 9. Each element is load-bearing -- removing the trap re-orphans the loop, restoring&&or||:re-swallows the failures. Against a real server the test passes 5/5 with the reference matched and no surviving clients.Genuine hits with reruns passing, last 30 days:
SIMILAR TOpattern matching predicate #101514,Stateless tests (amd_debug, distributed plan, s3 storage, parallel): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101514&sha=8ef111d9&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29 (UNKNOWN_TABLEsrc)Stateless tests (amd_tsan, parallel, 2/2): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106203&sha=1ab8ccf4f8982a98d856d7e6086616ffdff80de1&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%202%2F2%29 (UNKNOWN_DATABASE)The sibling
01169_alter_partition_isolation_stress.shstill useskill -TERM, but none of its recent failures carry this signature, so it is left for a separate change.Workflow [PR]
Sync PR [sync-upstream/pr/107883]