Skip to content

Report a test that exits at its timeout as a timeout, not a runner error, on macOS - #122522

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix/clickhouse-test-timed-out-exited-leader-macos
Sep 28, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix/clickhouse-test-timed-out-exited-leader-macos

Conversation

@groeneai

@groeneai groeneai commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #117779

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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) reported 05055_strict_resize_associated_output as Test internal error: ProcessLookupError [Errno 3] from os.getpgid(proc.pid) in process_result_impl (job). The same race raised PermissionError from os.killpg(pgid, SIGTSTP) and os.killpg(pgid, SIGTERM) in kill_process_group on #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 (returncode unset) and exited before the runner killed its group, so the leader was an exited process nobody had reaped. macOS hides such a process: getpgid returns ESRCH, and killpg skips 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:

  • pass proc.pid as the pgid: the leader is started with start_new_session=True, so its pgid is its pid, and the pid stays taken until it is reaped (this was the runner's only getpgid of a child without an ESRCH guard);
  • kill_process_group ignores EPERM like ESRCH for every signal, not only for SIGKILL (that SIGKILL-only handler is folded in).

05264_clickhouse_test_timed_out_test_exited loads the runner as a module, like 05099, answers getpgid and killpg as macOS does when the group's last running member exits before SIGTERM, between SIGTERM and SIGKILL, or before SIGTSTP, and expects Timeout! 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 gives Timeout! 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 same process_result_impl lines; whichever of the two merges second resolves the conflict to kill_process_group(pgid, ...).


Workflow [PR]
Sync PR [sync-upstream/pr/122522]

Version info

  • Merged into: 26.10.1.885-master (included in 26.10 and later)

groeneai and others added 2 commits September 27, 2026 09:28
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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
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).

# Sev Finding Verdict Evidence / action
1 ⚠️ The runner test stopped at the first killpg and only checked that some signal was sent, so the relocated SIGKILL handler was never reached and a skipped SIGTSTP would still pass (05264_clickhouse_test_timed_out_test_exited.sh) AGREE, fixed @ f945c7e the test names the signal before which the group's last running member exits (SIGTERM, SIGKILL after SIGTERM, SIGTSTP) and checks the exact signals sent; removing the SIGTSTP call or the SIGKILL EPERM handling makes it fail
2 💡 ci/praktika/utils.py Shell._check_timeout and send_signal catch only ProcessLookupError AGREE, not changed only after a job-level timeout, in a watchdog thread, never observed; not the runner this PR fixes
3 💡 The test calls process_result_impl with a stand-in self AGREE, not changed same shape as 05099; a new attribute read fails loudly
4 💡 The folded handler logs while killing for every signal AGREE, not changed nothing parses the line; MESSAGES_TO_RETRY matches neither Operation not permitted nor No such process

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-48:20260927-103600

@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Sep 27, 2026
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f945c7e]

Summary: ✅


AI Review

Summary

This PR fixes a macOS-specific timeout race in tests/clickhouse-test: when a test exits at its deadline before the runner reaps it, process_result_impl now kills the original process group by the leader PID instead of re-querying the hidden leader's PGID, and kill_process_group now treats macOS's EPERM-on-zombie-group behavior the same way it already treated ESRCH. The new regression test covers the three relevant escape points around SIGTSTP, SIGTERM, and SIGKILL, and I did not find an unresolved correctness or coverage gap in the changed path.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit f945c7e.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.60% 79.50% -0.10%

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

Full report

@alexey-milovidov alexey-milovidov self-assigned this Sep 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 28, 2026
Merged via the queue into ClickHouse:master with commit 9b44c4e Sep 28, 2026
172 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 28, 2026
alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Sep 28, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants