Repository navigation
Report a test that exits at its timeout as a timeout, not a runner error, on macOS - #122522
Conversation
When a test outlives its timeout, the `proc.wait` in `run_single_test`
raises `TimeoutExpired` and leaves `returncode` unset, and
`process_result_impl` then kills the test's process group. If the test
finishes in between, its leader has exited but nothing has reaped it yet,
and macOS hides such a process (xnu-12377.1.9): `proc_exit` sets
`P_REF_DEAD` ("will not be visible via proc_find", bsd/kern/kern_exit.c),
so `getpgid` returns ESRCH (bsd/kern/kern_prot.c), and `killpg1` skips
`SZOMB` members of a process group and returns EPERM to a POSIX caller when
it found no other member (bsd/kern/kern_sig.c). Linux still reports the
pgid of such a process and signals a group of them without an error.
So on `Fast test (arm_darwin)` a test that exits at its deadline was
reported as `Test internal error` instead of `Timeout!`, and its group was
not killed: `ProcessLookupError` from `os.getpgid(proc.pid)` in
`process_result_impl` (05055_strict_resize_associated_output, ClickHouse#117779), and
`PermissionError` from `os.killpg(pgid, signal.SIGTSTP)` and from
`os.killpg(pgid, signal.SIGTERM)` in `kill_process_group`
(01674_executable_dictionary_implicit_key and 01474_executable_dictionary,
ClickHouse#89945).
Pass `proc.pid` as the process group id. The test is started with
`start_new_session=True`, so its leader is a session leader whose pgid is
its pid and cannot change, and the pid stays taken until the leader is
reaped. This also lets the kill reach members that outlived an exited
leader.
Let `kill_process_group` ignore EPERM like ESRCH for every signal it
sends, not only for SIGKILL: the runner's children run under its uid, which
XNU always lets it signal, so EPERM there means that no member is left to
signal. The SIGKILL-only handler that already did this for the same macOS
behaviour is folded into the common one.
The new test loads the runner as a module, answers `getpgid` and `killpg`
the way macOS does for such a group, and checks that the test is reported
as a timeout with its group signalled, with and without
`--capture-client-stacktrace`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The runner test for a test that exits at its timeout stopped at the first `killpg` and only checked that some signal had been sent, so it never reached SIGKILL, whose EPERM handling now lives in the common handler, and it would still pass if SIGTSTP were no longer sent with `--capture-client-stacktrace`. Let the test name the signal before which the group's last running member exits (SIGTERM, SIGKILL after a successful SIGTERM, SIGTSTP), answer every `killpg` from that signal on with EPERM, as macOS does for a group of exited but unreaped members, and check the exact signals sent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding over 2 rounds, 0 in the recheck) plus my own cold review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20260927-103600 |
|
Workflow [PR], commit [f945c7e] Summary: ✅ AI ReviewSummaryThis PR fixes a macOS-specific timeout race in Final Verdict
LLVM Coverage ReportMeasured on commit f945c7e.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +161 lines in 51 files (-141 lines lost coverage) · Details |
…ned-test-groups-on-abort Conflict with ClickHouse#122522 in `process_result_impl`: master passes `proc.pid` to `kill_process_group` instead of `os.getpgid(proc.pid)`, which fails with ESRCH on macOS for an exited, unreaped leader. Kept this branch's timeout path and record bookkeeping, calling `kill_process_group(pgid, ...)` with the `pgid = proc.pid` it already binds; same in the process management notes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Related: #117779
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Requested by @ alexey-milovidov on #117779.
Fast test (arm_darwin)reported05055_strict_resize_associated_outputasTest internal error: ProcessLookupError [Errno 3]fromos.getpgid(proc.pid)inprocess_result_impl(job). The same race raisedPermissionErrorfromos.killpg(pgid, SIGTSTP)andos.killpg(pgid, SIGTERM)inkill_process_groupon #89945 (01674_executable_dictionary_implicit_key,01474_executable_dictionary, job). 90 days: 3 such errors on arm_darwin, 0 on Linux.The test ran past its timeout (
returncodeunset) and exited before the runner killed its group, so the leader was an exited process nobody had reaped. macOS hides such a process:getpgidreturns ESRCH, andkillpgskips zombie members and returns EPERM when nothing else is left (xnu-12377.1.9,bsd/kern/kern_prot.c:227,kern_sig.c:1709-1718). Linux returns its pgid and signals such a group without error.Changes:
proc.pidas the pgid: the leader is started withstart_new_session=True, so its pgid is its pid, and the pid stays taken until it is reaped (this was the runner's onlygetpgidof a child without an ESRCH guard);kill_process_groupignores EPERM like ESRCH for every signal, not only for SIGKILL (that SIGKILL-only handler is folded in).05264_clickhouse_test_timed_out_test_exitedloads the runner as a module, like05099, answersgetpgidandkillpgas macOS does when the group's last running member exits before SIGTERM, between SIGTERM and SIGKILL, or before SIGTSTP, and expectsTimeout!and the exact signals sent. It fails on master with the CI traceback, with either change alone at the other escape point, and passes with both. On Linux a real timed-out test givesTimeout!and its group is killed with the old and the new runner.The 05055 run would now read
Timeout!: its own loop stops at 60 s, the same as Fast test's--timeout 60. My open #113393 edits the sameprocess_result_impllines; whichever of the two merges second resolves the conflict tokill_process_group(pgid, ...).Workflow [PR]
Sync PR [sync-upstream/pr/122522]
Version info
26.10.1.885-master(included in26.10and later)