Skip to content

Fix praktika job hang (exit 125) when timeout cleanup command misses - #109096

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-fix-praktika-timeout-cleanup-hang
Jul 7, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-fix-praktika-timeout-cleanup-hang

Conversation

@groeneai

@groeneai groeneai commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #109071

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

Stateless tests (amd_tsan, s3 storage, parallel, 2/2) jobs intermittently finished with a job-level ERROR (exit code 125) and empty results: [] (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):

if self.timeout_shell_cleanup:
    Shell.check(self.timeout_shell_cleanup, verbose=True)
    return                       # <-- never signals the launched process

When timeout_shell_cleanup is set, the watchdog ran that command and returned early, without ever sending SIGTERM/SIGKILL to the launched process group. The cleanup command is docker rm -f <container>, and its container name was derived a second time in Job.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 runs docker rm -f praktika_076d3e59c96c and removes nothing ("No such container"). With the cleanup a no-op and no signal sent, the inner docker run process 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):

[19:31:05] StopTesting: test run was stopped (see earlier output for the cause)
[21:40:32] WARNING: Timeout exceeded [9000] for [2475]
[21:40:32] Run command: [docker rm -f praktika_076d3e59c96c]   # different name than launched
[23:38:50] Error waiting for container: ... grpc: the client connection is closing
[23:38:50] error during connect: ... docker.sock ... EOF
[23:38:50] WARNING: Job timed out: [...], timeout [9000], exit code [125]

Fix:

  • _check_timeout: run timeout_shell_cleanup as 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-time timeout_shell_cleanup derivation. Runner._run already derives it from the final parametrized job name and uses the same container_name for both --name and docker rm -f, so the names always match.

A regression test (ci/tests/test_teepopen_timeout_kills_process.py) drives _check_timeout with 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

  • Merged into: 26.7.1.590 (included in 26.7 and later)

@groeneai

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. TeePopen(f"sleep 30", timeout=1, timeout_shell_cleanup="true") -> pre-fix the child runs the full 30s (rc 0), post-fix it is terminated in ~1s (rc -SIGTERM). The CI manifestation is the same shape: a wedged inner process the no-op docker rm -f <wrong-name> failed to remove, never signalled.
b Root cause explained? _check_timeout ran timeout_shell_cleanup then returned, never signalling the process group. The cleanup name was derived at Job.Config.__post_init__ construction time from the pre-parametrized job name, so docker rm -f praktika_<hashA> targeted a different container than the launched --name praktika_<hashB> (hashes diverge once parametrization appends the (amd_tsan, s3 storage, parallel, 2/2) suffix). No signal + no-op cleanup -> inner docker run never dies -> job hangs past 9000s -> exit 125.
c Fix matches root cause? Yes. (1) cleanup becomes a best-effort supplement, always fall through to SIGTERM/SIGKILL the group; (2) drop the construction-time name derivation so Runner._run (final parametrized name, same container_name used for --name and docker rm -f) is the single source of truth -> names always match.
d Test intent preserved / new tests added? New test ci/tests/test_teepopen_timeout_kills_process.py added. No existing test weakened.
e Demonstrated in both directions? Yes. Fails on pre-fix code (child runs full 30s, rc 0, wall-clock 32s) with message "the exit-125 hang"; passes with the fix (rc -SIGTERM, ~4s).
f Fix general, not a narrow patch? Yes. The early-return skipped termination for ANY docker job with a cleanup command, and the name mismatch affected ALL parametrized docker jobs. Both fixes are in the shared praktika harness, not the tsan/s3 lane specifically.
g Generalizes across inputs? Covered: cleanup-command-set path, no-cleanup path (both now terminate the group), and the non-docker / no_docker path (unchanged: timeout_shell_cleanup stays None, direct killpg).
h Backward compatible? Yes. No user-facing behavior, setting, or format change. timeout_shell_cleanup semantics only widen from "replace" to "supplement".
i Invariants / contracts preserved? Yes. timeout_exceeded is still set before cleanup (TIMEOUT result path preserved). Runner._run already sets timeout_shell_cleanup when unset, so removing the construction-time set changes no docker job's effective cleanup except to make the name correct.

Session id: cron:clickhouse-worker-slot-0:20260701-213200

@groeneai

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv @leshikus — could you review this praktika watchdog fix? TeePopen._check_timeout ran timeout_shell_cleanup and returned early, never signalling the process group; and the cleanup's docker rm -f name was derived from the pre-parametrized job name, so it never matched the launched --name. Together these hung ~25 stateless-s3 jobs into a 9000s-timeout exit-125 with empty results. Fix makes cleanup a best-effort supplement (always terminate the group) and lets Runner._run own the container name.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cfb2ac8]

Summary: ✅


AI Review

Summary

This 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

⚠️ Majors

  • [ci/praktika/utils.py:1063] self.process.poll() is not None only proves the shell leader has exited, not that the launched process group is gone. A concrete repro on the current head is TeePopen("sh -c '(sleep 6 &) ; exit 0'", timeout=1): the background sleep inherits the stdout pipe, wait blocks for about 6 seconds, but _check_timeout returns early here with timeout_exceeded == False, so the timeout no longer bounds the launched job. Suggested fix: cancel the watchdog only when the condition that makes wait finish is satisfied (or otherwise track group liveness independently), and add a focused regression test for a leader that exits while a child in the same process group outlives the timeout.
Tests
  • ⚠️ Add a regression test for the "leader exits, descendant survives in the same process group" case, for example sh -c '(sleep 6 &) ; exit 0' under a 1-second timeout. That closes the proof gap for the launched-process-group timeout contract and reproduces the current false-negative timeout path.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: keep timeout enforcement active until lingering descendants in the launched process group are gone, and add the focused regression test for that shape.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 2, 2026
Comment thread ci/praktika/utils.py Resolved
@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — dc6f3a6

CI fully finished (Finish Workflow + Mergeable Check: pass). Every check is green; zero failed tests. This is a praktika-harness-only change (ci/praktika/utils.py + ci/praktika/job.py + a new regression test), so the heavy test matrix is skipped by design.

Check / test Reason Owner / fixing PR
(none) - no failures
CH Inc sync - pass

Session id: cron:our-pr-ci-monitor:20260702-020000

Comment thread ci/praktika/job.py Outdated
).hexdigest()[:12]
)
self.timeout_shell_cleanup = f"docker rm -f {container_name}"
# NOTE: timeout_shell_cleanup for docker jobs is derived in

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 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.

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.

Done, removed in 2291add. Rationale kept in the commit message.

@groeneai
groeneai force-pushed the ci-fix-praktika-timeout-cleanup-hang branch from dc6f3a6 to 2291add Compare July 2, 2026 11:06
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jul 2, 2026
Comment thread ci/praktika/utils.py Resolved
@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 2291add

CI 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).

Check / test Reason Owner / fixing PR
(none) - No failed checks on this head

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]>
Comment thread ci/praktika/utils.py
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:

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.

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"?

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 7, 2026
Merged via the queue into ClickHouse:master with commit 57116db Jul 7, 2026
175 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 7, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…meout-cleanup-hang

Fix praktika job hang (exit 125) when timeout cleanup command misses
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 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