Repository navigation
Do not let an orphaned test process wedge the functional-test pipeline - #112265
alexey-milovidov merged 9 commits into
Conversation
Internal second-model review (10 rounds, 46 findings adjudicated) - click to expandBefore opening this pull request I ran it through an independent cold review plus a separate Round 10 (final)
I also raised, and then withdrew, a concern that the test teardown's Round 9
Earlier rounds (all agreed and fixed unless noted)
Session id: cron:clickhouse-review-slot-8:20260728-101100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-45:20260727-235100 |
|
cc @maxknv @leshikus - could you review this? It stops a per-test wrapper process that outlives @leshikus, flagging one interaction with your stacktrace work in the same file: one of the new tests drives |
|
Workflow [PR], commit [5ba6cfb] Summary: ✅ AI ReviewSummaryThis PR fixes the functional-test runner so per-test wrapper shells no longer inherit the runner's own Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 5ba6cfb.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +225 lines in 65 files (-63 lines lost coverage) · Details |
…line
`Stateless tests` jobs have been failing with a job-level `error` that burns the
full wall-clock budget and reports no per-test results at all: `check_status`
is `error` and `results` is empty, so the failure is invisible to every
test-name-based query. Over the last 30 days this happened 16 times across 14
unrelated pull requests and 0 times on master.
In CI the runner heads a shell pipeline,
`clickhouse-test | ts | tee -a <file>` (`ci/jobs/functional_tests.py`). A
per-test wrapper is spawned with `start_new_session=True` and inherited stdio,
so it holds the pipeline's write end and lives in its own session. When the
runner aborts and exits, a wrapper that outlives it keeps that descriptor open,
`ts` and `tee` never see EOF, and the pipeline never finishes. The job-level
wall-clock timeout then replaces the runner's real exit status, which is why
the underlying `Server died` report is never produced and no per-test rows are
written.
The wrapper does not need the runner's streams: the command already redirects
the test's own output to the per-test `{stdout}`/`{stderr}` files that
`process_result_impl` reads back, so the inherited descriptors carried nothing.
Its stdout is now `DEVNULL` and its stderr is appended to the per-test stderr
file, which removes the coupling without reaping anything. The parallel workers
and the bookkeeping manager keep the runner's stdout by design, since they
report results through it; fd 0 is likewise still inherited.
Also fixed here, found while validating the above:
- The per-test stderr file is truncated before each attempt, so a retried
attempt no longer inherits the previous one's diagnostics, and the wrapper
appends rather than overwrites, since the command's own `2> {stderr}` holds a
second descriptor on that path with its own offset.
- A `preexec_fn` that dies before `exec` is now reported as the test's failure
with its numeric exit status, instead of being lost.
Documented in `tests/clickhouse-test-process-management.md`.
Verified in the job's own image with a live server: the pipeline finishes with
the runner's status while the orphan is deliberately left running, and
reverting the redirect reproduces the wedge.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111693&sha=005d71edc8389539f2661acd34f2bd165de3b108&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112265&sha=afd4ae8bc5b3cbfa78cad8f1bf5e0a5a66c33b54&name_0=PR&name_1=CI%20Tests
Related: ClickHouse#111693
Related: ClickHouse#112265
Co-Authored-By: Claude Fable 5 <[email protected]>
afd4ae8 to
897bb1d
Compare
|
The re-run of this PR's workflow (attempt 2 of run 30397395779, created 2026-07-28) checks out refs/pull/112265/merge as it stood then, so the tested tree was this head merged with master at 71ec9af (2026-07-28 19:52 UTC). That tree predates c5b976c (PR ClickHouse#112385, merged 2026-07-29 14:35 UTC), which pins --enable_parallel_replicas 0 in 01666_merge_tree_max_query_limit.sh. Without that pin the holder query becomes several reads of the same table on the same server and is rejected by its own max_concurrent_queries = 1 slot, so the last throttle assertion sees no holder. Merging master brings the pin onto the branch, so the outcome no longer depends on which merge base CI picks. Pinned master: 6764095
Cut the added comment block above report_cgroups_unavailable from seven lines to two and folded the four blocks around the spawn into two. What is gone is motivation and history rather than any invariant: that a per-function cache_ignore_args closure makes the report per process and a suite with both parallel workers and sequential tests therefore emits it up to --jobs + 1 times; that the workers and the bookkeeping manager keep the runner's stdout by design; that open(path, "wb") truncates, which the mode already says. Also restored the pre-existing comment above pattern. It describes a 2>> that fe90c97 had already replaced with 2>, so it was stale before this branch and correcting it is not this change's business. The property the append-mode open depends on is stated where that open is. Comments added by this change to tests/clickhouse-test: 20 -> 10, against 10 added code lines, with no block longer than three lines.
The teardown removed every clickhouse-test-* directory that appeared at the
cgroup root during the run. Appearing after the snapshot does not establish
ownership: the CI Tests job runs --cgroupns=host, so a co-scheduled runner's
directory is visible, and it is removable while still empty in the window
between its os.makedirs and its memory.max write. This teardown could therefore
delete it and make that runner's preexec_fn fail. On the machine this was
developed on, /sys/fs/cgroup held 220 such directories from other processes.
run_single_test names the cgroup clickhouse-test-{os.getpid()}, and
TestCase.__init__ builds the per-test file names in that same process, so
<test>.<pid>.stdout carries exactly the owning worker's pid. A path is now
removed only if it is both new and attributed that way, so a recycled pid from an
earlier run is not adopted, and an unattributed new path is left alone rather
than reported, which keeps a foreign directory from turning into a false failure.
The PGID files are not usable: run_single_test unlinks each one when its test
finishes, so none survives a teardown that runs after the runner has exited. That
leaves the attribution able to come up empty, so the test asserts it did not - in
the body, not in the finally, where it would mask a real failure. Nothing is
added to that set unconditionally, the runner's own pid included, because that
would make the assertion unfalsifiable; this fixture carries no sequential tag,
so its spawns happen in workers.
Checked against a fake cgroup root, since makedirs under cgroupfs fails as a
non-root user and the shipped test creates no directory there at all: ours empty
is removed, ours non-empty survives and is reported leaked, a foreign directory
survives and is never reported, one named after a pid present before the run
survives, and the pid really does come from the artifact name. The same state run
through the previous loop deletes the foreign directory. Breaking only the
artifact match, with every call site left as it ships, fails this test and no
other.
A pid still identifies the owner only within this container, which does not share
the host's pid namespace, so a directory another container created inside the
snapshot window under a colliding pid would match. That is narrower than what it
replaces, and closing it needs a host-unique token in the name, which is the
runner's to choose; noted where the filter is.
Also deleted the comment above `pattern`. It describes a `2>>` redirect that
fe90c97 had already replaced with `2>`, and the properties that matter here
- that the test's own redirect truncates and holds a second descriptor with its
own offset - are stated where the append-mode open is. And dropped the runner
class from one skip reason: the job moved to RunnerLabels.ARM_SMALL, and the
Linux-only point the reason makes does not depend on which one it is.
Correction to 897bb1d's message, which said the bookkeeping manager
reports test results through the runner's stdout: only the workers run
run_tests_array and print assembled results. The manager processes host the
shared queue and the restarted-tests list. Both do hold the runner's stdout, and
both are deliberately out of the invariant's scope, which is what that paragraph
was about.
CI finish ledger - 897bb1d
That run is attempt 2 of a workflow created 2026-07-28, so it checked out Two other changes in this push, unrelated to that red:
One thing worth flagging: Session id: cron:clickhouse-maint-slot-12:20260828-012700 |
Ledger discharge - 0342f70The ledger on the previous head owned the CI is finished at this commit with zero failures (praktika Session id: cron:our-pr-ci-monitor:20260828-070000 |
On an ASan build, a stateless run that aborts on the hung check records no
stack of the hung server anywhere:
Hung check failed: server is not responding
Cannot collect C stacktraces under ASan: debugger attach is disabled.
Two things combine to produce that. print_c_stacktraces declines to attach
lldb on ASan builds, because a ptrace attach disables LeakSanitizer for the
rest of the process; that refusal is correct and stays. And
print_sql_stacktraces, the collector that needs no debugger at all, was
unreachable in this state: its availability pre-check went through
check_server_liveness, which probes HTTP on http_port (default 8123), while
the collector itself shells out to args.client on the native TCP port
(default 9000). Those are different listeners on different ports served by
different code paths, so a server whose HTTP endpoint is wedged or whose
handler pool is exhausted while TCP still answers queries failed the gate and
was never asked. That is precisely the reported signature: the process alive,
not responding. The hung-check abort site did not call the SQL collector in
the first place, and neither did the FailureReason.SERVER_DIED site.
Drop the pre-check and let the bounded TCP query be its own liveness test.
The reason the pre-check existed was to keep "Code: 210 Connection refused"
tracebacks out of every failed run, and that concern is now covered where it
belongs: get_stacktraces_from_clickhouse runs under shell_get_output with
timeout=30, which caps a dead or wedged socket at 30 seconds and reduces a
failure to a single trim_for_log-bounded stderr line with no traceback. The
existing "if bt:" guard still means nothing is written and nothing is claimed
when nothing was collected; an else branch now records that the attempt was
made, so "tried and got nothing" is distinguishable from "never tried".
Then add the SQL dump to the two abort sites that had only the C path. It
goes before the C dump for the reason the per-test timeout handler documents:
dump while the client connections are still up, because once they drop the
server cancels the wedged queries and their threads disappear.
A server-side alternative was considered and rejected. Sending SIGTSTP so the
server logs its own stacks would work mechanically, but onFault emits its
report at LOG_FATAL, check_fatal_messages_in_logs greps for any <Fatal> line
and appends a result carrying Result.Label.BLOCKER, and FuzzerLogParser
classifies "Received signal" as a signal failure. The diagnostic would have
manufactured a merge-blocking failure out of itself, which is worse than the
present silence. Teaching those scanners a benign exception was rejected too:
six independent consumers key on those strings, so it would weaken real-crash
detection in six places for a diagnostic gain. Nothing in this change writes
to the server log.
This does not fix any hang, and it does not restore C++ stacks on ASan
builds. What it changes is that a server alive but not answering HTTP now
yields the full system.stack_trace view with per-thread thread_name and
query_id, which identifies the query that wedged the server.
Measured on a live server, with HTTP dead and TCP live: master skips and
writes nothing, this change writes a 357 KB sql_stacktraces.log carrying
thread_name and query_id. An abort with HTTP wedged rather than closed gets
9.7 seconds faster, because the pre-check itself blocked for 10 seconds and
then collected nothing; the worst case is 20 seconds slower when both
transports are wedged, bounded by timeout=30. Green runs are unaffected,
since no caller runs on a passing test.
Regression coverage goes in the existing ci/tests/test_print_stacktraces.py.
The oracles key on the sql_stacktraces.log artifact and its columns, or on
per-site call order, never on stdout: the unfixed code, the rejected
call-site-only variant, and print_c_stacktraces all print lines, so a test
asserting that some output appeared would pass in every case and measure
nothing. The two abort sites are asserted independently, because the per-test
timeout handler and the end-of-run hung-query check already called both
collectors and would otherwise mask a revert of either new site.
Related: ClickHouse#42701
Related: ClickHouse#112265
…-wrapper-stdio-wedge One conflict, in tests/clickhouse-test. 182a59e ("Remove the old-analyzer test mode") deleted cache_ignore_args together with its only user, is_old_analyzer_used; this branch had added a second user of that decorator, report_cgroups_unavailable. Resolved by taking the deletion and decorating report_cgroups_unavailable with functools.cache instead: it takes no arguments, so the "ignore args" helper that existed for non-hashable ones has nothing left to do here, and functools.cache keeps the same per-process, once-per-notice behaviour the notice relies on. Keeping the helper alive for this one caller would have restored code master deliberately removed. tests/clickhouse-test-process-management.md described the old decorator by name, so it is updated to match. Everything else merged cleanly: master's 662 added lines in tests/clickhouse-test since 6764095 do not touch the spawn path, and the five files this branch owns are unchanged by it.
The `CI Tests` job that ran `pytest ci/tests/` was removed in 8ff3720 ("Remove the `CI Tests` job along with `ci/tests`", 2026-08-22), together with `ci/jobs/ci_tests_job.py`, `JobConfigs.ci_tests` and the `ci_tests` lane in `.github/workflows/pull_request.yml`. No current job executes `ci/tests`: `ci/defs/defs.py` and `ci/defs/job_configs.py` register none, and the stateless job selects from `tests/queries`, so these files and their digest inputs are never reached. `.claude/CLAUDE.md` states the position directly: a throwaway test for a CI-script change does not need to be committed, because there are no automated CI tests. So the three files this branch added under `ci/tests` could not fail, could not report, and re-created a directory the repository had deleted. They are removed here rather than left as 740 unreachable lines in front of a reviewer. The change under test is unaffected: the invariant, its two producers and the reason each half of the `open` pair is load-bearing stay documented in tests/clickhouse-test-process-management.md, whose now-dangling pointer to the deleted module is dropped with them. The suite was run one last time against this merge before deletion: all five pass on this tree, and the same five against master's own tests/clickhouse-test fail four (the fifth is the no-regression guard on output collection, which master passes by construction), so the fix is still load-bearing after master's 662 added lines in that file.
Merged master; the
|
The `ci/tests` suite that covered this change was dropped in 0a04b3f, because 8ff3720 removed the `CI Tests` job together with the directory, so nothing ran it. That left the load-bearing pieces of the spawn without any check that runs in CI: they could be reverted and every job would still be green. This ports the coverage to the stateless suite, following 05099_clickhouse_test_keeper_retry_matching.sh: load `clickhouse-test` as a module and drive `run_single_test` with the `Popen` seam replaced by a stand-in that records how the streams were handed over and then replays what the real wrapper does to the per-test files, including the fatal `preexec_fn` path that exits before bash execs. No server, no sockets and no wall-clock threshold, so it is not a new flake source under the sanitizer jobs; it runs in 0.7 s. Every element has a mutation arm that reddens only the reference lines it owns, measured against the runner in this branch: stdout=subprocess.DEVNULL "wrapper stdout is not the runner's own", for dropped, and for stdout=1 or subprocess.STDOUT: the oracle resolves the handed descriptor against the runner's own stdout, so neither a plain fd nor another negative sentinel passes in its place stderr=wrapper_stderr "wrapper diagnostic reaches the collected stderr", plus the append line below the "ab" mode "wrapper stderr lands after the test's own", which collects `Terminated\nites this to its own stderr\n` under "wb" - the clobbering of a ` <Fatal> ` line that append prevents open(stdout_file, "wb") the two lines for a wrapper that dies before exec, where the post-wait normalization raises FileNotFoundError; and, for "ab" in place of "wb", "earlier attempt's stdout is cleared" open(stderr_file, "wb") "earlier attempt's stderr is cleared", which needs the truncation rather than the file, since the append open that follows creates it anyway Against master's runner verbatim the whole reference differs and `clickhouse-test` reports [ FAIL ].
…-wrapper-stdio-wedge
ClickHouse#121387 made `run_single_test` call `get_timeout`, which reads `flaky_check` and `no_self_parallel` from the test case arguments and `is_concurrent` from the test case. The stand-in built by `make_case` had none of them, so `run_single_test` raised `AttributeError` before it reached the replaced `Popen`, and the test failed in the merge queue with a `TypeError` on `seen`. With the attributes set to their defaults the test passes against the merged runner again, and against master's runner (without the spawn change) all seven reference lines still differ. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=gh-readonly-queue/master/pr-112265-00721e1919652f65821d92356b3d8eea5848f8d2&sha=3b6d2a99a5abb1aa1963c91a8df6d403053f2eeb&name_0=MergeQueueCI&name_1=Fast%20test Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The merge queue run failed on |
…ned-test-groups-on-abort Keep ClickHouse#112265's new stdio invariant section in the process management document ahead of the renamed PGID-tracking section; the rest merged cleanly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#112265 the per-test wrapper gets its own stdout and stderr, so a group that outlives the run no longer holds the pipeline the runner heads. Two comments still gave that as the reason the group must be reaped; say only that it stays live, which is still true. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`clickhouse-test --cleanup` calls `cleanup_test_groups` without `worker_pids`, so it must not parse record names: on a reused runner `ci/tmp` can hold a record of a killed invocation (another token) and one an older runner wrote as `clickhouse_test_group_pid.<worker>`. Nothing covered this after `ci/tests` was removed. The new arm writes both, calls `cleanup_test_groups` and checks that both groups are killed and both records removed. It fails if the sweep starts parsing names (the legacy record is skipped) or filtering on the token (the killed invocation's record is skipped), while the other tests of the module stay green in both cases. Also drop the module docstring's claim that a regression here brings back the hung `clickhouse-test | ts | tee` pipeline: since ClickHouse#112265 a test group no longer holds the runner's stdout or stderr. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Stateless testsjobs fail with a job-levelerrorafter burning the full wall-clock budget, and uploadno per-test results (
results: []), invisible to any test-name query: 16 times in 30 days across14 unrelated pull requests, 0 on master:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111693&sha=005d71edc8389539f2661acd34f2bd165de3b108&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29
ci/jobs/functional_tests.pyheads the pipelineclickhouse-test ... | ts | tee -a <file>, andTestCase.run_single_testspawned each test with nostdout/stderr, so the per-test wrapper shellinherited the write end of that pipe. The wrapper has its own session and
StopTestingnever reaps it, soon an abort the orphan keeps the pipe open,
ts/teenever see EOF, and praktika's watchdog kills the jobbefore
FTResultsProcessor.runruns.The wrapper now gets its own sink:
DEVNULLfor stdout, and for stderr the per-test file the harnessalready collects, in append mode so bash's job-control diagnostic lands after the test's own output
instead of overwriting a
<Fatal>line thatprocess_result_implpromotes toSERVER_DIED. 227instrumented spawns carried zero bytes on either inherited stream.
Scoped to per-test wrappers and their descendants; workers and
multiprocessing.Managerprocesses keepthe runner's stdout deliberately. It does not reap orphans or fix the hung-check false positives.
Covered by
05218_clickhouse_test_wrapper_stdio_contract.sh: a stateless test that loadsclickhouse-testas a module and drivesrun_single_testwith thePopenseam replaced, with noserver and no timing threshold. Each of the five elements has a mutation arm reddening only its own
reference lines, and against master's own
tests/clickhouse-testthe runner reports[ FAIL ]. Itreplaces the
ci/testssuite dropped in0a04b3fcwhen8ff3720644b2removed theCI Testsjob.Workflow [PR]
Sync PR [sync-upstream/pr/112265]
Version info
26.10.1.849-master(included in26.10and later)