Repository navigation
Conversation
Fast test on ClickHouse#86768 reported "Failed: 0, Passed: 73, Skipped: 23" and still failed, with a synthetic "Server died" leaf. No test failed and the server never crashed: no fatal message, no core, no sanitizer report. The server saturated (not died) at 15:02:02 and stopped admitting new queries. Keeper heartbeats and cleanup scheduling kept flowing, while 33 of 51 liveness requests logged "Creating query context from session context" with no executeQuery after it. The per-test alarm is int(args.timeout * 1.1) + 60, and Fast test passes --timeout 60, so the budget is 126 s. Because the stall was server-wide rather than specific to one test, all 24 workers armed and fired at once. The first worker into timeout_handler called stop_tests(), which reaches os.killpg(pgid, SIGTERM) on our own process group. Every worker and the parent share that group, so one test exceeding its own deadline SIGTERMed the entire run. clickhouse-test then exits -15, which is in ABORTED_RUN_EXIT_CODES, so FTResultsProcessor relabels a fully green run as "Server died". The two errors visible in the job log are downstream of that kill, not independent problems: Code 76 on ci/tmp/run_r0/status, because teardown runs prepare_logs(all=True) before terminate() and so dumps system tables while the server still holds its flock, and Code 159, because SYSTEM FLUSH LOGS then flushes a four-minute query_log backlog on an already-saturated server. A per-test timeout was using a whole-run teardown primitive. Extract the per-child walk from cleanup_child_processes into kill_out_of_group_children and call only that from timeout_handler, so the timing-out worker reaps its own out-of-group clients and then raises TimeoutError, reporting one honest failed test. cleanup_child_processes keeps its own-pgid broadcast unchanged, so the whole-run callers (server-died, KeyboardInterrupt, stop-requested, --stop-time) behave exactly as before. The --max-failures paths already skip stop_tests() for this reason, and their comments name the same "143 / Server died" hazard. This is suite-agnostic; Fast test just has the shortest fuse. It does not address the saturation itself, which is a separate load question. After this change a saturated server yields per-test TIMEOUT failures, which is a louder and more accurate signal than one mislabelled leaf. The defect is in the harness, so no SQL test can observe it. The new ci/tests test drives the real timeout_handler body with os.killpg, os.getpgid, pgrep and kill_process_group faked, and asserts two counters so it cannot pass vacuously: broadcasts to our own group must be 0, while the out-of-group child must still be killed. A third check pins that cleanup_child_processes still broadcasts, which is the highest-risk failure mode of the extraction. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: no blocking findingsAn independent model re-reviewed this diff cold. One nit, not adopted. 💡 Two further nits I raised myself and withdrew on evidence: the comment's reference to |
|
Workflow [PR], commit [d03d2a8] AI ReviewSummaryThis PR fixes the primary bug well: a single per-test timeout no longer sends Missing context / blind spots
Findings
Tests
Final VerdictNeeds changes. |
|
cc @leshikus @pamarcos, could you review this? A per-test SIGALRM in clickhouse-test was calling stop_tests, whose killpg broadcasts SIGTERM to our own process group, which every parallel worker and the parent share, so one test exceeding its own deadline terminated the whole run and the job side relabelled a fully green run as "Server died"; the handler now reaps only the timing-out test's own out-of-group clients. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 5 s compile time in total, 7 of them have a recent master baseline. |
The per-test SIGALRM is raised as a TimeoutError from wherever the worker happens to be. TestCase.run converts it into a TIMEOUT result only while its own `except socket.timeout` arm is unspent (socket.timeout is TimeoutError on Python 3.10+). Raised past that point, for example inside run's `except (ConnectionError, ...)` arm while check_server_liveness is retrying, nothing converts it: it escapes run, `except TimeoutError: break` leaves test_result as None, and the reporting path dereferences None. The worker dies with AttributeError, the parent sets runner_process_killed, and the run exits 1 without ever reporting the test. check_server_liveness can spend 165 s (10 bounded socket reads plus backoff) against a 126 s alarm at --timeout 60, so the window is reachable. The structure predates this branch; killing the process group used to preempt it, so leaving the worker alive is what makes it observable. Complete whichever step the alarm interrupted: - synthesize a TIMEOUT result when none exists; - format it when process_result did not finish, since the job-side leaf regex in ci/jobs/scripts/functional_tests_results.py matches only stamped lines and an unstamped one attributes the failure to clickhouse-test; - report the measured duration rather than the configured --timeout, matching every other path in run. Both guards are one-directional, so an already-computed verdict is never replaced or double-stamped. The regression arms drive the real run_tests_array and assert against the parser's own regex, read from its source rather than copied. Reverting the fix, never re-formatting, dropping either guard, or restoring the constant duration each reddens an arm. Alarms are raised directly rather than timed, so no arm depends on the wall clock; 250/250 on repeat.
|
Confirmed and fixed in bfef5cc. The claim is correct, and my earlier reasoning about it was wrong. I had argued that Driving the real
Reachability: the alarm budget is Two related defects turned up while fixing it, both included:
Both guards are one-directional, so an already-computed verdict is never replaced or One point I did not act on: a timed-out test still leaves its per-test database behind, |
process_result stamps a result's status marker by mutating description in place and only then returns, while the caller records that in a separate local. An alarm delivered between the two left the flag saying "not formatted" about an object that already was, so the recovery arm formatted it again. A doubled description is not cosmetic. The second stamped line also matches the job side's per-test leaf pattern (functional_tests_results.py), whose consumer has no dedup, so the run reported an extra failing test that never existed - the same class of embedded match that pattern's bounded prefix was added to rule out. Blocking SIGALRM across the format call makes the two stores indivisible rather than tracking the discrepancy. Pending signals are not lost: delivery happens at the mask restore, so a real deadline is still reported. Making the formatter non-mutating was the alternative, but run() mutates description at four further sites and changing one of them would be an inconsistent half measure. The existing regression only raised before the formatter, leaving this sub-window untested. The new arm raises after it and asserts a single leaf, that the alarm was still delivered, and that the mask is clean afterwards - so deferring cannot silently become dropping.
CI finish ledger - 9a8c54aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Everything else on this head is green: 79 success, 97 skipped, 1 failure. Not caused by this PR. The diff is Session id: cron:our-pr-ci-monitor:20260817-170000 |
|
Fixing PR for the It does not fix the |
| TestStatus.NOT_FAILED, | ||
| ) | ||
| if test_result is None or test_result.status not in survives: | ||
| test_result = TestResult( |
There was a problem hiding this comment.
test_result is None is still conflating two different states here. signal.alarm(0) only runs after test_case.run returns, but TestCase.run computes result, then does _cleanup() at tests/clickhouse-test:3982 and finally remove_settings_from_env() at tests/clickhouse-test:2393-2395. If the deadline lands in either of those tail-cleanup windows, TestTimeout escapes before line 4871 assigns test_result, so this branch rewrites an already-known FAIL / UNKNOWN / NOT_FAILED to TIMEOUT.
That same remove_settings_from_env window can also leak per-test state because the worker now survives. A targeted repro that raises TestTimeout between the two stores reports the first test as Timeout! and the following test inherits CLICKHOUSE_CLIENT_OPT=LEAK_OPT. To preserve the new survivor contract, either hand the computed TestResult back before post-verdict cleanup starts, or block/cancel SIGALRM around _cleanup() and env restoration and add a regression for that exact window.
There was a problem hiding this comment.
Both windows re-derive at the head you read (7c2399a8), and the two halves of the claim came out differently, so I judged them separately.
The env leak is real, and I have fixed it. A real SIGALRM delivered between the two stores of remove_settings_from_env, against the real function built from two source trees:
unfixed: CLICKHOUSE_CLIENT_OPT='LEAK_OPT' deadline raised
fixed : CLICKHOUSE_CLIENT_OPT='' deadline raised
It persists to the third test, so it is permanent for the worker, and you are right that the survivor contract is what makes it observable: before this PR the worker died, so no following test existed to inherit anything. I took the deferral shape rather than a wider try, and confirmed masking defers rather than swallows, so the deadline is still raised immediately afterwards and the test is still failed.
Masking narrows that window but cannot close it: the signal can arrive after run enters its finally but before the mask takes effect, and the single restore call is then already spent, leaving both variables dirty. So the recovery path repeats the restore where no alarm is armed; both stores are idempotent.
The verdict rewrite does not reproduce. A deadline in _cleanup is raised through run's finally, so the environment is restored and the deadline recorded: reported [ FAIL ], exit 1, nothing escapes. No known verdict is rewritten to something weaker.
Looking at the survivor set again because of your comment, though, I found the inverse bug and fixed it: SKIPPED was surviving its own deadline, and it is reachable after a test has executed (@@SKIP@@, cloud post-filters, blacklists). Unlike FAIL, UNKNOWN and NOT_FAILED it does not fail the run, so a timed-out test was reported as a skip with exit code 0. Only the statuses that fail the run survive now.
Two regressions exist to keep the suite honest: one refuses the restore for a whole attempt, and one times out the first of two tests, since every previous driver test used a one-element queue and so could have been satisfied by a run that stops after reporting one test. Each mutation reddens exactly one oracle.
Also squashed to 5 commits.
…ment A per-test deadline used to end the whole run: the handler called `stop_tests`, whose `killpg` broadcasts SIGTERM to the process group that every parallel worker and the parent share. The job side then read the resulting exit -15 as "Server died", hiding a run in which every test that executed had passed. The handler now kills only the timing-out test's own out-of-group clients. Surviving the deadline is half the contract; the run must then report the test exactly once, and correctly: - The deadline is raised as `TestTimeout`, which is not an `Exception` subclass. `signal.alarm` is armed once per attempt and never re-armed, so a deadline absorbed by one of the `except Exception` handlers around the pre-test health check left the attempt running with no deadline at all. - A deadline delivered while a verdict was being formatted, or from the `finally` that cancels the alarm, is recorded rather than propagated, so it can neither escape the loop nor be dropped. - FAIL, UNKNOWN and NOT_FAILED outlive their own deadline, because each already fails the run and names a more specific problem. Nothing else does. `SKIPPED` in particular is reachable after a test has executed (`@@Skip@@`, cloud post-filters, blacklists) and does not fail the run, so keeping it reported a test that never finished as one the run may ignore, with exit code 0. - `remove_settings_from_env` restores two variables and every later test captures them as its own baseline, so a deadline between the two stores left the timed-out test's client options installed for the rest of the worker's life. The stores are now indivisible, and because masking only narrows that window, the recovery path repeats the restore where no alarm is armed; both stores are idempotent. The window was previously unreachable in every one of these cases: the worker died, so no following test existed to observe anything. The regressions drive the real `run_tests_array`, including the default `--testname` path, with real signals. Two of them exist to keep the suite honest: one refuses the environment restore for a whole attempt, and one times out the first of two tests so the suite cannot be satisfied by a run that stops after reporting a single test.
7c2399a to
d03d2a8
Compare
|
If a test fails, the CI will fail anyway, so we don't need continuing testing. |
|
Understood on the premise, and I am not asking you to reopen this on the "keep testing" argument. One thing I want to put on record before dropping it, because it is not about continuing the run. The failure that produced this PR had zero failing tests. All 73 executed Fast tests passed on #86768; the run was aborted by a per-test alarm, and the job side turned that into a synthetic The mechanism is in Measured on CIDB, 30 days: 90 runs across 53 PRs got a Worth noting the "don't mislabel an abort as a server death" principle is already in this file three times, and none of them are mine: So the smaller change that precedent suggests is just that: stop the run as it does today, but exit with a dedicated code so the job side reports a timeout instead of If that shape is worth having I will open it as a separate minimal PR. If you would rather leave the mislabel alone, say so and I will close this out and not revisit it. |
Related: #86768
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
The problem.
Fast teston #86768 reportedFailed: 0, Passed: 73, Skipped: 23yet failed with a syntheticServer diedleaf. No core, no sanitizer report.Report | job log
Root cause. The server saturated rather than died, so all 24 workers hit the 126 s alarm at once. The first into
timeout_handlercalledstop_tests(), whichkillpgs our own group, shared by every worker and the parent. One test's deadline thus SIGTERMed the whole run, exiting -15, whichABORTED_RUN_EXIT_CODESmakes the job side relabelServer died. TheCode: 76onrun_r0/statusand theCode: 159fromSYSTEM FLUSH LOGSare downstream of it.The change.
timeout_handlernow kills only the timing-out test's own out-of-group clients, via a per-child loop extracted fromcleanup_child_processes. That broadcast is unchanged, so the whole-run callers are unaffected, as the--max-failurespaths document.A surviving worker must then report the test, which needs a result built and stamped. The alarm can land before either, so the recovery arm completes what is missing, and
SIGALRMis blocked across stamping so it cannot run twice: a doubled description matches the leaf pattern too, reporting a nonexistent test.Fast test just has the shortest fuse. This does not fix the saturation.
Validation. Not SQL-observable. The new
ci/tests/test drives the real handler andrun_tests_array, fakingkillpg/pgrep: own-group broadcasts 0, the test's own client still killed,cleanup_child_processesstill broadcasting, one parseable leaf per alarm window. No wall clock.ci/tests/is 663/665, both failures pre-existing.Residuals. A timed-out test's database and temporary directory survive into the worker's next test, as when the alarm killed the worker outright. An alarm can also be swallowed by an unrelated broad
except Exception, after which saturation reportsSERVER_DIED, as master did on every per-test timeout. Both want a private signal type, a larger change.Workflow [PR]
Sync PR [sync-upstream/pr/115061]