Skip to content

Wait for the worker cleanup before force-killing the test workers - #115403

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/stop-budget-outlasts-sanitizer-grace
Sep 20, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/stop-budget-outlasts-sanitizer-grace

Conversation

@groeneai

@groeneai groeneai commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #113393

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

No related open issue; found while investigating Stress test (*) jobs failing with only
script exit code: 1.

do_run_tests stopped a run by SIGTERMing each worker and waiting join(timeout=10) before SIGKILLing it.
That worker's SIGTERM path reaches kill_process_group, which on a sanitizer build sleeps 60 seconds,
so every worker got 10 seconds for a 60 second cleanup and died inside that sleep.

Two consequences. The sanitizer report is truncated, which is what the grace in 1a76ce9b81ce3fc exists to
collect. And p.kill() reaches only the worker, not the test's process group, whose PGID file is already
unlinked, so the test's bash and clickhouse-client survive. The harness's random query killer then kills
that leaked client and the orphaned bash writes Terminated into the log descriptor it inherited. Landing while the job packages the logs, tar exits 1 on file changed as we read it, killing the job before the hung check.

The wait is now derived from the delays cleanup sleeps for, so the two cannot drift apart again;
ddc6bcfbd68a761's SIGTERM, wait, SIGKILL, wait escalation is unchanged. Workers clean up concurrently, so
the grace is one monotonic deadline for all of them, and a ceiling rather than a sleep.

It bounds one cleanup invocation, not the whole cleanup: a worker owning several process groups pays the
sleeps per group and its later groups are still cut short. No wait is shorter than the previous 10 seconds,
so nothing regresses. Remaining gaps below.

Aggregate shutdown grows: N wedged workers cost 70 + (N-1)*10 seconds on a sanitizer lane, 80 + (N-1)10
with stacktrace capture, against N
10 before, so about +60s on 16 workers. Cheap against losing a report,
but it is CI wall-clock.

A unit test pinning the budget was removed on review request, so it rests on the CI stop-path runs.

Affected runs, validation, #113393

All four are sanitizer lanes over three weeks, base_ref=master. In each the worker log stops after the
SANITIZED-gated print, never reaching Killing process group, and the archived log is 11 bytes short.
Release and debug lanes, which skip that sleep, show none. Also uncovered: the stacktrace collection, an
uninterruptible sleep, and spawn workers (aarch names), which have no cleanup.

Before the test was removed, eleven mutations each reddened it distinctly (flat 10s, no kill()
escalation, unbounded wait, sleep instead of ceiling, per-worker budget, either delay dropped, floor gone,
wall-clock deadline, call site reverted). End to end with real processes, the pre-change shape leaks the
bash and writes those 11 bytes 3/3; this change eliminates it 3/3.

#113393 (mine, open) extracts this same sequence into quiesce_workers_and_reap() and keeps
p.join(timeout=10) verbatim, relocating this defect without fixing it. Complementary (that one reaps
orphaned groups, this one stops creating them) but textually conflicting. I can rebase onto it or fold this
in there.


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

Version info

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

When the run is stopped abnormally (server death, hung check, global time
limit, --max-failures), the parent SIGTERMs each worker and waited 10 seconds
before SIGKILLing it. A worker's SIGTERM path reaches kill_process_group,
which on a sanitizer build deliberately sleeps 60 seconds so the sanitizer can
print its report. The parent therefore gave every worker 10 seconds to finish a
cleanup that takes 60, and killed all of them inside that sleep.

Two things are lost when that happens. The sanitizer report is truncated, which
is what the 60 second grace exists to collect (1a76ce9). And p.kill()
reaches only the worker, not the test's process group, whose PGID file has
already been unlinked - so the test's bash and clickhouse-client survive. When
the stress harness's random query killer then terminates that leaked client,
the orphaned bash writes "Terminated" into the log file descriptor it
inherited, after the parent has moved on. If that write lands while the stress
job is packaging the logs, tar reports "file changed as we read it" and exits
1, and the job fails at the packaging step with no other diagnostic - skipping
the hung check, which runs afterwards. In four such stress runs the archived
log and the raw log differ by exactly 11 bytes: "Terminated\n".

Derive the wait from the same values the worker's cleanup sleeps for, so the
two cannot drift apart again, and keep the escalation from ddc6bcf:
SIGTERM, bounded wait, SIGKILL for stragglers, bounded wait. The sanitizer
grace is one deadline shared by all workers, because they clean up
concurrently and giving each its own would multiply the stop time by the number
of workers. The previous 10 seconds is kept as a floor under every individual
wait: the workers have all been terminated by the time the wait loop starts, so
a shared deadline on its own would let the first slow worker consume it and
leave the rest with no wait at all - killing more workers mid-cleanup than the
loop being replaced did. With the floor, the worst case is the grace plus 10
seconds per worker. The budget is a ceiling and not a sleep, so a worker that
exits promptly is not delayed, and the deadline is read from a monotonic clock
so that a clock adjustment during the stop cannot truncate a wait.

The guarantee is bounded to the delays the cleanup sleeps for, and three things
sit outside it. On a build with --capture-client-stacktrace, kill_process_group
goes on to collect a stacktrace per client process after those sleeps; that
step is unbounded in the number of clients, so it is deliberately not folded
into the budget. A process in uninterruptible sleep outlives any budget. And
under the spawn start method, selected when the check name contains aarch, a
worker re-imports the module without the __main__ block, so it never installs
the SIGTERM handler and runs no cleanup for a wait to outlast; this change
neither causes nor worsens that, and none of the four runs above is such a job.

A build with no sanitizer and no --capture-client-stacktrace keeps the previous
10 seconds per worker, at any worker count. With capture enabled the budget
covers that delay too, which is what the functional test and Fast test lanes
use.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Aug 19, 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; 0 findings on the published tree;
bounded: 1 full pass + 2 fix rounds + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ❌ The shared deadline gave 10 s total where the loop it replaced gave 10 s per worker, so on a --capture-client-stacktrace lane it killed more workers mid-cleanup than the code it replaced AGREE, fixed @ fec0788 join now takes max(deadline - monotonic(), WORKER_STOP_MARGIN_SECONDS), a floor equal to the previous per-worker allowance; the shared grace is kept. 6 config rows x N in {1, 8}, every case at or above the old allowance
2 ⚠️ The new deadline was computed from the wall clock, which this file itself flags as non-monotonic; a forward step truncates a later worker's wait AGREE, fixed @ fec0788 monotonic used at the two new deadline sites only. Two clock-discontinuity tests added; the four pre-existing wall-clock deadlines and args.stop_time left untouched
3 ⚠️ No test could see the production call site: reverting it to the inline flat 10 s sequence left the whole suite green AGREE, fixed @ fec0788 One inspect.getsource(do_run_tests) arm, plus a mutation that restores the inline sequence and now reddens exactly that arm
4 ⚠️ "Non-sanitized builds keep the previous 10 seconds" was false on the capture lanes, where the budget is 20 s AGREE, fixed @ 4b096dd Corrected in the body, commit message and test docs, and pinned by a test asserting the relationship rather than a literal
5 ⚠️ test_real_clock_is_used_in_production was vacuous (X is time.time or callable(X)) and was reddened by zero mutations AGREE, fixed @ 4b096dd Deleted; the property it gestured at is already pinned by two other arms
6 ⚠️ A CI fix whose case rests on four runs cited no report URLs AGREE, fixed @ 4b096dd Four canonical report URLs added, all verified reachable
7 ❌ The budget covers the cleanup's sleeps but not the per-client stacktrace collection that follows them AGREE on the gap, DISAGREE on the prescribed remedy I did not bound or skip that collection: it is unbounded in client count and removing it would delete the diagnostics the flag exists to gather. Finding 1's floor is what makes the gap non-regressive. Stated as a limitation in the description instead
8 ⚠️ Under the spawn start method a worker installs no SIGTERM handler, so it has no cleanup at all AGREE on the defect, DISAGREE on fixing it here Different root cause, and this change neither causes nor worsens it. None of the four runs is such a job. Disclosed in the description rather than folded in
9 💡 Four nits: a dead cc line, a stale control row in the mutation matrix, an unexplained margin constant, and a literal-valued filter in one test that could under-count AGREE, fixed @ 4b096dd none

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.

The final pass over the published tree returned 0 findings. Independently of the review, I
confirmed the mechanism against the preserved artifacts rather than the write-up: in each of the
four runs the worker log stops after the print that sits inside the sanitizer-gated branch and
never reaches the unconditional line after the sleep, and the archived member is 11 bytes shorter
than the raw log, those bytes being Terminated.

Session id: cron:clickhouse-review-slot-8:20260819-055800

@clickhouse-gh clickhouse-gh Bot added manual approve Manual approve required to run CI labels Aug 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6c8b118]

Summary: ✅


AI Review

Summary

This PR replaces the parent’s flat join(timeout=10) with a monotonic deadline derived from the worker cleanup delays. That improves the sanitizer-report case, but it still does not wait for the whole pre-kill cleanup on --capture-client-stacktrace jobs, so the orphaned-test-group failure mode remains reachable there.

Findings

⚠️ Majors

  • [tests/clickhouse-test:758-829, 1107-1127; ci/jobs/fast_test.py:375; ci/jobs/functional_tests.py:137-139] [dismissed by author -- https://github.com/Wait for the worker cleanup before force-killing the test workers #115403#discussion_r3811087493] terminate_workers only budgets worker_cleanup_grace_seconds() plus the fixed margin, but kill_process_group still runs the per-client lldb loop before it ever sends the first SIGTERM/SIGKILL to the test process group. Fast and functional jobs explicitly enable --capture-client-stacktrace, and get_stacktraces_from_lldb allows 30 seconds per client, so one slow attach is enough to exhaust the 20s/70s budget and p.kill() the worker before the test PGID is reaped. That recreates the same orphaned-bash / late-log-write path this PR is meant to close on those lanes. Suggested fix: either move the destructive group kill ahead of the lldb collection, or include the full pre-kill capture phase in the worker budget with an explicit ceiling.
Final Verdict

Changes requested: the sanitizer-only underwait is improved, but the worker-stop contract is still violated on --capture-client-stacktrace lanes.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A harness drives the real terminate_workers against a real worker whose SIGTERM handler runs the real kill_process_group, with a real bash -c test group holding the inherited fd. Pre-change: the worker is SIGKILLed at the wait, its bash and client survive, and 11 bytes of Terminated\n land in the log after the parent moved on. 3/3 runs, no flakiness.
b Root cause explained? The parent's abnormal-stop wait was join(timeout=10), but a worker's SIGTERM path reaches kill_process_group, which on a sanitizer build sleeps 60 s to let the sanitizer print. 10 < 60, so the worker is SIGKILLed inside that sleep. p.kill() does not reach the test's process group and the PGID file is already unlinked, so the test's bash and clickhouse-client are orphaned; when the random query killer terminates that client, the orphaned bash writes Terminated into the inherited log fd, which is what tar then reports as file changed as we read it.
c Fix matches root cause? Yes. The wait is derived from the delays that same cleanup performs, so the parent stops killing workers mid-cleanup. The sanitizer grace is one shared deadline, since workers clean up concurrently, with the previous 10 s kept as a floor under every individual wait so that no worker is given less time than before. No tar status is tolerated, no no-random-* tag, no widened bound, no defensive guard at the symptom site. It also restores the sanitizer report the 60 s grace exists to collect, and the hung check that the packaging failure was skipping.
d Test intent preserved / new tests added? Yes. No pre-existing test weakened or removed. New ci/tests/test_clickhouse_test_stop_budget.py: 15 tests, including a negative control that fails loudly if the fake worker stops modelling the defect, a guard that the module load does not patch the shared os module, and a source-level arm asserting the production stop branch still calls the budgeted helper (without it, reverting the call site to the historical inline wait left every other test green). The two harness guards were verified non-vacuous by mutating the harness rather than the source, since no source mutation can reach them.
e Both directions demonstrated? Yes. Pre-change shape reproduces the 11-byte write 3/3 and the worker never completes its cleanup; with the change the cleanup completes, killpg is reached, no process survives, 0 late bytes, 3/3. On master all new tests error on the absent helper, so eleven mutation arms are the real discriminator and each reddens for its own reason.
f Fix is general across code paths? Yes on the fork start method. join(timeout= appears exactly twice in the file, both in this one sequence; all four abnormal-stop triggers (server death, hung check, global time limit, --max-failures) enter that same branch, so all four are fixed together. Upgrade check shares clickhouse-test and benefits identically. Fixed at the origin rather than guarded at the packaging call site. Under spawn, selected only when the check name contains aarch, a worker re-imports without the __main__ block, installs no SIGTERM handler and runs no cleanup, so there is nothing for a wait to outlast; that is a different defect, this change neither causes nor worsens it, and none of the four runs is such a job.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, for the axes that exist here: the full SANITIZED x CAPTURE_CLIENT_STACKTRACE x RELEASE_NON_SANITIZED matrix is asserted (5 combinations, including that the two delays are additive when both apply), and the worker-count and worker-behaviour axes are covered (1 vs 8 workers; exits promptly, uses its full grace, never exits). Every one of those configurations was checked at 1 and 8 workers to confirm no worker is given less time than the loop this replaces gave it. A wall-clock step forward and backward during the stop are also covered. Datatype and type-wrapper axes are N/A: this is CI harness code with no column types.
h Backward compatible? (maintainer-approved exception only) Yes. CI-only. No product code, no setting, no SettingsChangesHistory.cpp, no serialization or format surface, no experimental gate. A build with neither a sanitizer nor --capture-client-stacktrace keeps the previous 10 s per worker exactly, at any worker count; with capture on, the wait grows to cover the delay that cleanup also sleeps for. Both rows are pinned by tests. The only other observable difference is that one existing log line now interpolates the constant it already stated.
i Invariants and contracts preserved? Yes. The invariant is that a parent stopping a child must wait at least as long as the delays that child's cleanup sleeps for, that no worker gets less than it did before, and that the escalation after it is still bounded. It does not claim to cover the whole cleanup: the client stacktrace collection that follows those sleeps is unbounded in the number of clients and deliberately not folded in. ddc6bcfbd68a761's contract is intact: SIGTERM, bounded wait, SIGKILL for stragglers, final bounded join, so the hang it fixed stays fixed (three mutation arms pin this; worst case is the grace plus 10 s per worker, measured). The deadline is monotonic, so a clock adjustment mid-stop cannot truncate a wait. The SIGTERM mask around the sequence is untouched, so the STOP_TESTING_EXIT_CODE / Server died reporting contract is unchanged, confirmed by test_max_failures_exit_code passing against a live server.

Session id: cron:clickhouse-impl-slot-5:20260819-051400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @azat @leshikus, could you review this? The parent's abnormal-stop wait was a flat join(timeout=10) while the worker's own SIGTERM cleanup sleeps 60 s for the sanitizer report, so every worker was SIGKILLed inside that sleep, truncating the report and orphaning the test's process group. The wait is now derived from the delays that cleanup actually sleeps for, keeping the previous 10 s as a per-worker floor and the bounded escalation from ddc6bcfbd68a761 intact.

Comment thread tests/clickhouse-test
for p in processes:
if p.is_alive():
p.terminate()
deadline = monotonic() + worker_cleanup_grace_seconds() + WORKER_STOP_MARGIN_SECONDS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deadline still stops at worker_cleanup_grace_seconds() + WORKER_STOP_MARGIN_SECONDS, but on every --capture-client-stacktrace lane the worker cleanup does more work before it ever reaches the os.killpg(..., SIGTERM/SIGKILL) that actually reaps the test group. In cleanup_child_processes this path calls kill_process_group(..., None), so client_printed_stacktrace can never short-circuit and the worker always iterates pgrep(..., command="clickhouse") and calls get_stacktraces_from_lldb for each child. Each attach allows up to 30 seconds, so a single slow client trace already exceeds the 10-second margin and the parent can still SIGKILL the worker before it kills the test PGID, recreating the orphaned-bash / tar: file changed as we read it path on the functional, fast, and stress jobs that always pass --capture-client-stacktrace.

Either include the client-stacktrace phase in the budget, or move the group-kill ahead of the potentially long lldb loop.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lldb phase is genuinely outside the budget, and the PR says so: "the stacktrace collection after them is not counted". It is deliberate. That loop is unbounded in the number of clients, and #114565 raises its per-PID ceiling to 120s, so folding it in would make the stop time scale with client count. Bounding or reordering it is a change to what the capture flag collects, which is a separate concern from this mismatch.

Two corrections to the premise. Stress jobs do not pass --capture-client-stacktrace on the worker path: grep -c capture-client-stacktrace tests/docker_scripts/stress_runner.sh is 0, and run_func_test does not pass it. The only stress use is stress.py:912, the separate single-test hung-check invocation, which is not a terminate_workers path. None of the four affected runs had capture enabled, so this is not the mechanism behind them.

On the functional and Fast test lanes, which do pass it, the budget already includes client_stacktrace_delay_seconds(), and the floor keeps every individual wait at the previous 10s, so no worker gets less time than before this change. A slow lldb attach can still outlast the budget there - that is the disclosed residual, unchanged by this PR and not introduced by it.

@PedroTadim PedroTadim self-assigned this Aug 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6c8b1180d with master dabcc4cde (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.37 MiB 701.33 MiB -3.04 MiB (-0.43%)

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 units

9 translation units recompiled, 14 s compile time in total, 9 of them have a recent master baseline.

Job report

@@ -0,0 +1,446 @@
"""
`tests/clickhouse-test`: the abnormal-stop wait must outlast the worker cleanup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groeneai remove this test file

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 871e2f4.

It pinned the parent's wait to the delays kill_process_group sleeps for, rather than to the constants, so a later retune of either delay could not silently reintroduce the mismatch. That is the only coverage lost; the fix itself is unchanged. If you want the property guarded without a unit test, I can add a stress-lane assertion instead - happy either way.

Requested in review. The test pinned the parent's wait to the delays
kill_process_group sleeps for, rather than to the constants, so that the two
could not drift apart again. The fix in tests/clickhouse-test is unchanged; it
is now covered only by the CI runs that exercise the stop path.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread tests/clickhouse-test
WORKER_STOP_MARGIN_SECONDS = 10


def terminate_workers(processes):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix no longer has any committed regression coverage for the derived stop budget. A future retune of SANITIZER_REPORT_GRACE_SECONDS / client_stacktrace_delay_seconds or a reversion to the inline join(timeout=10) sequence would stay green unless a stress or functional lane happens to reproduce the orphan leak again.

Please add the smallest focused runner-level test or deterministic CI assertion that exercises the abnormal-stop path and fails when the parent under-waits its workers.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coverage was removed on request: @ PedroTadim asked for ci/tests/test_clickhouse_test_stop_budget.py to be deleted (thread above), and I complied in 871e2f4. Restoring it here would revert that instruction, so I am not re-adding it.

Your point splits in two, and only one half is open:

  • A retune of either delay cannot reintroduce the mismatch. worker_cleanup_grace_seconds derives the budget from the same symbols the sleeps use: SANITIZER_REPORT_GRACE_SECONDS at tests/clickhouse-test:745 versus the sleep at :788, and client_stacktrace_delay_seconds() at :747 versus the sleep at :801. Both sides move together by construction, which is the property the deleted test pinned.
  • A reversion to a hardcoded join(timeout=10) would go green with nothing to catch it. That is real and I am not claiming otherwise.

For that second half I offered a non-timing stress-lane assertion in the deletion thread and it is still on the table: one commit whenever either reviewer wants it. I am not pushing a replacement unasked a few hours after a maintainer removed the previous coverage.

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai 🕵️

Premise checks out and the mechanism is right — a worker really can be inside kill_process_group's sleep(60) when the parent terminates it (process_result_impl calls it for a timed-out test, and the sleep is gated on SANITIZED alone), so the old flat join(timeout=10) killed it at second 10 and lost the report. Also confirmed collect_build_flags sets SANITIZED / RELEASE_NON_SANITIZED in main (line 5848) before do_run_tests (6130), so the parent computes a real grace rather than silently getting 0.

One thing before it lands: worker_cleanup_grace_seconds() models a single kill_process_group invocation, but the worker's SIGTERM path can run several. stop_tests() → cleanup_child_processes() loops over children whose pgid differs from the worker's own and calls kill_process_group(child_pgid, None) for each, so on a sanitized build that's 60 * K seconds of sleeps against a deadline of 70 + 10. K is normally 0 (the worker's own group is SIGTERMed directly, without sleeping), but the comment at lines 777-787 says groups escaped via timeout(1) do happen — which is exactly the messy shutdown this patch targets. With K >= 1 the worker is still killed mid-cleanup, just later. The per-child get_stacktraces_from_lldb calls under CAPTURE_CLIENT_STACKTRACE are uncounted too.

Not a regression — every case is strictly better than 10s — so this is fine to merge as an improvement. But I'd either widen the grace for the multi-group case, or make the K=0 assumption explicit in the docstring; "the wait must outlast that cleanup's sleeps" reads as a guarantee that only holds for one invocation.

Two minor notes:

The floor's rationale ("they are all already terminated, so a shared deadline alone would give the last ones no time at all") doesn't quite hold: workers clean up concurrently, so once the deadline passes they have each already had the full wall-clock grace. The floor's real value is covering a worker that was slow to start cleanup — same code, better reason.
Worth stating in the PR body that aggregate shutdown can grow: N wedged workers now cost 80 + (N-1)10 versus N10, so ~+70s on a 16-worker run. Cheap next to losing a sanitizer report, but CI wall-clock is a live concern.

worker_cleanup_grace_seconds() models the sleeps of ONE kill_process_group
call, but a worker's SIGTERM path can run several: cleanup_child_processes
loops over children whose pgid differs from the worker's own and calls
kill_process_group per child, so the sleeps are paid once per group. The
docstrings read as a guarantee that only held for a single invocation.

Measured with the shipped cleanup_child_processes in the real worker
topology (kill_process_group counted, not executed): a worker holding one
live test child gives one differing-pgid group, and a worker that killed a
timed-out test's group without reaping it and then started the retry gives
two. So the single-group case is the ordinary one rather than an empty one,
and the multi-group case is reachable on exactly the messy shutdown this
change targets.

No behaviour change. The grace is deliberately left at one invocation:
widening it to K groups makes the stop time scale with a quantity the
parent cannot observe before it waits, and every wait is already strictly
longer than the flat 10s it replaced, so no case regresses.

Also corrects the floor's stated rationale. Workers clean up concurrently,
so once the shared deadline passes each has already had the full wall-clock
grace; the floor's real value is covering a worker that was slow to start
its cleanup.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

@PedroTadim Your citations check out at the head, and the K >= 1 point is right, but K = 0 is not the normal case. I measured it with the shipped cleanup_child_processes in the real worker topology, counting kill_process_group calls instead of executing them:

  • worker holding one live test child: K = 1 (the test's bash runs under start_new_session=True, so its pgid always differs from the worker's)
  • worker that killed a timed-out test's group without reaping it, then started the retry: K = 2 (the unreaped child is still a differing-pgid entry, alongside the new one)
  • worker with no children: K = 0

So the ordinary sanitized case is 60s against a 70s deadline, which fits, and the two-group case is 120s against 70s, which does not. Your reading of the escape path is right, it is just one level lower than timeout(1).

I took the docstring route, not the widening. Widening to K groups means the parent budgets a quantity it cannot observe before it starts waiting, and the sleeps are sequential per group, so the honest bound is unbounded in child-group count. Every wait is already at least the previous 10s, so the multi-group case is late rather than regressed. Both docstrings now say the budget covers one invocation and that later groups are still cut short, and I dropped the uncounted 0.1s SIGTERM-to-SIGKILL gap in as well since it is the same class of omission as the lldb collection.

The floor's rationale is corrected to yours: it covers a worker slow to start its cleanup, not one that has already had the grace.

Aggregate growth is in the body, measured rather than derived: N wedged workers cost 70 + (N-1)*10 seconds on a sanitizer lane, 80 + (N-1)10 with stacktrace capture, against N10 before. About +60s on 16 workers.

6c8b118, docstrings and body only, no behaviour change.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6c8b118

CI is fully finished on this head and no check failed, so the table below has no rows
and nothing needs an owner.

Check / test Reason Owner / fixing PR

Measured on the deduplicated check-run set (newest attempt per name): 171 unique names,
0 incomplete, 0 non-green, 73 succeeded and 98 were skipped by the selected-tests gate.
No name has a superseded cancelled attempt in the raw list (172 raw runs against 171
unique), so there is no retry ambiguity here. Config Workflow, Style check and
Finish Workflow all succeeded, which makes this a real run rather than a void one.

The skipped majority is expected for a change confined to tests/clickhouse-test: the
fuzzer, performance, ClickBench, upgrade and packaging legs are not selected. What did
run is the part that exercises the harness itself, and it is the part that matters here:
all 10 Stress test legs across amd and arm for asan_ubsan, debug, msan, tsan, release
and arm s3, plus 13 builds, Fast test, Fast test (arm_darwin), CI Tests,
Code Review, 18 stateless legs, the 8 Integration tests (amd_llvm_coverage) shards,
LLVM Coverage, Unit tests (amd_llvm_coverage) and Build profile diff.

CIDB agrees independently for this head: 177176 OK test rows and 0 FAIL or ERROR
rows.

Since the change alters when the stress harness force-kills its test workers, the green
Stress test sweep across all 10 sanitizer and storage combinations is the relevant
signal, and it is clean.

Session id: cron:our-pr-ci-monitor:20260820-173000

@PedroTadim PedroTadim removed their assignment Aug 25, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 4, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 19, 2026
Merged via the queue into ClickHouse:master with commit 661768f Sep 20, 2026
176 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 20, 2026
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-oranjeai PR origin: delegated from the OranjeAI sibling fleet 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.

4 participants