Repository navigation
Fix praktika job hang (exit 125) when timeout cleanup command misses - #109096
alexey-milovidov merged 1 commit into
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260701-213200 |
|
cc @maxknv @leshikus — could you review this praktika watchdog fix? |
|
Workflow [PR], commit [cfb2ac8] Summary: ✅ AI ReviewSummaryThis PR fixes the original Praktika timeout-cleanup hang by always signalling the launched process group and by moving docker cleanup-name derivation to the final parametrized job name. That part looks directionally right, but the new early-exit backstop now treats "the shell leader exited" as equivalent to "the launched job is finished", which lets a lingering descendant process bypass the timeout entirely. I would request changes for that regression. Findings
Tests
Final Verdict
|
CI finish ledger — dc6f3a6CI fully finished (Finish Workflow + Mergeable Check: pass). Every check is green; zero failed tests. This is a praktika-harness-only change (
Session id: cron:our-pr-ci-monitor:20260702-020000 |
| ).hexdigest()[:12] | ||
| ) | ||
| self.timeout_shell_cleanup = f"docker rm -f {container_name}" | ||
| # NOTE: timeout_shell_cleanup for docker jobs is derived in |
There was a problem hiding this comment.
@groeneai, remove the comment - it makes sense only in the pr context. Don't write comments explaining deleted code blocks - after the merge, there is no context it can relate to.
There was a problem hiding this comment.
Done, removed in 2291add. Rationale kept in the commit message.
dc6f3a6 to
2291add
Compare
CI finish ledger — 2291addCI fully finished and clean on this head. No failed checks: Finish Workflow, Mergeable Check, Config Workflow, CI Tests, Style check, Code Review, and PR all pass. The heavy test matrix is skipped by design for this praktika-harness-only change (ci/praktika/utils.py + ci/praktika/job.py + regression test).
Session id: cron:our-pr-ci-monitor:20260703-093000 |
TeePopen._check_timeout ran timeout_shell_cleanup and returned early, never signalling the launched process group. The cleanup command is docker rm -f <container>, whose name was derived at Job.Config construction time from the pre-parametrized job name, so it targeted a different container than the one launched with --name at run time and removed nothing. The inner docker run was then never terminated and the job hung past its timeout until an unrelated docker-daemon event closed the pipe, producing a job-level ERROR (exit code 125) with empty results. Terminate the launched process group first so timeout enforcement never depends on the external cleanup returning, then run the best-effort cleanup in a bounded daemon thread. A cleanup that wedges on a hung docker daemon can no longer re-introduce the hang. Drop the construction-time timeout_shell_cleanup derivation so Runner._run is the single source of truth, computing the container name from the final parametrized job name so docker rm -f always matches the launched --name. The watchdog also slept the full timeout unconditionally, so a child that finished early still tripped it: it marked timeout_exceeded, ran the cleanup, and, in a long-lived process, issued a late killpg against an already-reaped and possibly PID-recycled process group that could belong to an unrelated job. Wait on an event set when the child is reaped (with poll() as a backstop) instead of a blind sleep, so an early-exiting child cancels the watchdog before it marks a timeout or signals anything. Add regression tests that drive _check_timeout with a no-op cleanup, no cleanup, a blocking cleanup, and an early-exiting child, asserting the launched process is terminated promptly when it overruns and that the watchdog stays silent when the child finishes first. Co-Authored-By: Claude Opus 4.8 <[email protected]>
2291add to
cfb2ac8
Compare
| return | ||
| # Backstop for the race between the wait timing out and the child | ||
| # exiting: if the process is already gone, enforce nothing. | ||
| if self.process.poll() is not None: |
There was a problem hiding this comment.
self.process.poll() is not None is too weak as the "child finished" check here. The timeout contract is for the launched process group, but poll() only tells us the shell leader exited. With the current code, TeePopen("sh -c '(sleep 6 &) ; exit 0'", timeout=1) returns after about 6 seconds with timeout_exceeded == False: the background sleep stays in the same process group and keeps the inherited stdout pipe open, so wait() still blocks, but this branch makes the watchdog return without ever sending killpg.
That means the new early-exit backstop reintroduces a timeout bypass for commands that let descendants outlive the leader. Can we key this bailout off the same condition that proves wait() is really done (or otherwise track group liveness separately), and add a regression test for "leader exits, child in the same group outlives the timeout"?
…meout-cleanup-hang Fix praktika job hang (exit 125) when timeout cleanup command misses
Related: #109071
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Stateless tests (amd_tsan, s3 storage, parallel, 2/2)jobs intermittently finished with a job-level ERROR (exit code 125) and emptyresults: [](28 occurrences across 25 PRs in the last 30 days; 0 on master). No individual test failed; the job wrapper itself hung and then errored.Root cause is a bug in the praktika watchdog
TeePopen._check_timeout(ci/praktika/utils.py):When
timeout_shell_cleanupis set, the watchdog ran that command and returned early, without ever sending SIGTERM/SIGKILL to the launched process group. The cleanup command isdocker rm -f <container>, and its container name was derived a second time inJob.Config.__post_init__at construction time, from the pre-parametrized job name. Parametrization later appends the(amd_tsan, s3 storage, parallel, 2/2)suffix, so the two hashes diverge: the container is launched with--name praktika_6ec74b80afda, but cleanup runsdocker rm -f praktika_076d3e59c96cand removes nothing ("No such container"). With the cleanup a no-op and no signal sent, the innerdocker runprocess was never terminated, so the job hung well past its 9000s timeout until an unrelated docker-daemon event closed the pipe, yielding exit 125.Observed in the job.log tail (PR #108493):
Fix:
_check_timeout: runtimeout_shell_cleanupas a best-effort supplement and always fall through to terminate the launched process group. A timeout that does not kill the process defeats the watchdog.Job.Config: drop the construction-timetimeout_shell_cleanupderivation.Runner._runalready derives it from the final parametrized job name and uses the samecontainer_namefor both--nameanddocker rm -f, so the names always match.A regression test (
ci/tests/test_teepopen_timeout_kills_process.py) drives_check_timeoutwith a no-op cleanup command and a child that outlives the timeout, asserting the child is terminated promptly. It fails on the pre-fix code (child runs its full sleep, exit 0, wall-clock >= child sleep) and passes with the fix.Version info
26.7.1.590(included in26.7and later)