Repository navigation
Bound each statement of the stateful data preparation - #115585
alexey-milovidov merged 2 commits into
Conversation
prepare_stateful_data ran its whole script through one Shell.run with no
timeout and no per-statement bound. The script is set -e with an ERR trap, so
a statement that fails is named and aborts the step, but a statement that
never returns is not an error: set -e never fires, the trap never runs, and
Shell.run blocks in proc.wait(). The only terminator left is praktika's job
watchdog at 9000s, which SIGKILLs the job. clickhouse-test never starts, CIDB
receives only a job-level error row with an empty test_name, and the server
logs that would identify the hang are never uploaded, because a killed job
never reaches COLLECT_LOGS. Measured 5 times in 60 days, all amd_tsan, on 5
different PRs and never on master, each silent for 8414s or more.
Every statement is now prefixed with
timeout --verbose --signal=TERM --kill-after=60 N
A bound reached exits 124, or 137 after the kill, which set -e turns into a
real failure and the existing trap names via $BASH_COMMAND, so no new
diagnostic machinery is needed. The job then fails fast, so log collection
runs and preserves the evidence.
N is derived from the job's own budget rather than hardcoded: 35 percent, so
3150s at the current 9000s budget. That is 3.3x the worst prep wall-clock
observed over 40 healthy job logs (965s; worst amd_tsan 675s) and above the
script's own MAX_EXECUTION_TIME of 1800s, so it cannot pre-empt a legitimate
INSERT, while the recorded hangs all exceeded 8414s.
Three measured constraints shaped the mechanism.
Shell.run(timeout=) is not usable: it SIGTERMs the process group, so there is
no exit code for the trap and stderr is empty (rc=-15, stderr=''). It bounds
the run and loses the diagnostic, which is the whole point of the change.
The bound is per statement, not one wrapper around the script. Against a
child that ignores SIGTERM, the realistic shape of a client wedged in a
syscall or a lock wait, a single wrapper either does not bound at all without
--kill-after, or SIGKILLs the trap's own shell with it, leaving the statement
unnamed. SIGKILL is uncatchable, so only a per-statement bound keeps the
naming. A shell-function wrapper is no substitute either: bash does not
inherit ERR into functions without errtrace, so it bounds and produces no
trap line at all.
The bound is threaded in from functional_tests.py, which holds a live Info,
because Info() raises FileNotFoundError outside a job. It reads JOB_CONFIG as
a mapping, not an attribute: _Environment.from_dict ends in
cls(**filtered_obj) and rebuilds no nested dataclass, so JOB_CONFIG arrives
as a plain dict inside the job and attribute access would raise in every
stateless functional-test job. A regression arm pins that contract.
A local run passes no bound and renders a byte-identical script, so nothing
changes for a developer's laptop. Deliberately no numeric fallback: a missing
job budget means a local run, so a default would mask a real harness bug in
CI, where the value is instead required and an unusable one fails loudly.
The new test asserts six independent properties, including the two contrasts
above, since a bare "is it bounded?" assertion stays green without them. Each
has a mutation arm and each mutation reddens its own assertion.
This does not fix the hang itself, whose root cause is still unknown. It
bounds an unbounded step and preserves the logs needed to find it.
The safety arm compared the derived bound against hand-copied 9000 and 1800. That checks the arithmetic, not the property the design sells: that the bound follows a retuned job budget. Lowering common_ft_job_config.timeout to 3600 drops the bound to 1260 s, under the 1800 s max_execution_time the prep script itself grants its INSERTs, so the bound would pre-empt legitimate work while the arm stayed green. Both limits now come from production: the job timeouts by enumerating every config that runs functional_tests.py (61 today, 59 at 9000 and 2 at 18000) and max_execution_time by parsing the script source. Each inequality is asserted per job, and both readers fail loudly when their matcher goes stale rather than silently matching nothing. Adds the missing half of the log-preservation claim: after a bound hit the worst path is bound + kill grace + teardown + collect logs, and that has to fit the job budget or the server logs the fix exists to preserve are still cut off. 5910 < 9000 and 9060 < 18000 today. The jobs are matched by duck typing because ci/defs/job_configs.py imports praktika.job while this file imports ci.praktika.job; those are distinct module objects, so isinstance against Job.Config matches nothing. WORST_HEALTHY_PREP_S corrected 965 -> 1010 after re-measuring the prep interval over 30 job logs across 7 flavours, and the per-arm narrative that duplicated the commit message and PR body is trimmed.
Internal second-model reviewA second model reviewed this change independently over two rounds, and I reviewed it cold each time Fixed after review
💡 💡 Test narrative trimmed. The incident recap and the rejected alternatives live in the commit Corrected in my own earlier analysis ❌ I had recorded that Disagreed, with evidence ❌ "The two dataset-script statements are not bounded, because the wrapper ❌ "Late stateful re-preparations can outlive the outer watchdog, since each gets 35 % of the ❌ "Bound or skip the teardown flush before log collection." The citations are right but the ❌ Noted, not blocking 💡 The residual, in its corrected and narrower form: for the two 💡 |
|
Workflow [PR], commit [fc266f5] Summary: ✅ AI ReviewSummaryThis PR adds per-statement Findings
Tests
Final VerdictChanges requested. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260820-070700 |
|
cc @maxknv @leshikus, could you review this? |
| with_s3_storage=is_s3_storage, | ||
| is_db_replicated=is_database_replicated, | ||
| build_type=bugfix_bt, | ||
| step_timeout=stateful_prep_step_timeout(info), |
There was a problem hiding this comment.
The fixed stateful_prep_step_timeout(info) value still loses the race you are trying to close in the bugfix-validation loop. These jobs run the first build with global_time_limit=0 (functional_tests.py:1129), then call prepare_stateful_data again for each of the three later build swaps. On the current 18000s bugfix jobs that gives every later re-prepare a fresh 6300s statement timeout even if most of the job budget has already been spent, so once the earlier test runs have taken more than 11700s the outer watchdog can still SIGKILL the job before timeout fires; and once they have taken more than 8940s, there is no longer enough budget left for the timeout + teardown + COLLECT_LOGS path anyway. In other words, a late hang in the build_types[1:] re-prepare path still falls back to the original "no trap line / no uploaded logs" failure mode. This needs to be derived from the remaining job budget (or fail explicitly when too little budget remains), not from the job's initial timeout.
There was a problem hiding this comment.
The arithmetic is right, and the 8940 s arm is the same scenario as the watchdog arm rather than a
second one: 18000 - 6300 - 60 - 1800 - 900 = 8940 is the same derivation with the log-preservation
reserve substituted for the watchdog, so both describe one race with two entry thresholds.
It is not reachable. The build_types[1:] re-prepare is gated on test_result.is_ok()
(functional_tests.py:1165), so a run only reaches :1256 if the first build's tests passed. Over
90 days exactly 2 of 20239 bugfix-validation runs ever passed 8940 s elapsed, and both died inside
clickhouse-test (StopTesting on PR111622, proc.wait on PR105984), so is_ok() was false in
both and neither entered the loop. aarch64 never exceeds 3008 s.
Both remedies you name cost more than they save. Sizing from remaining time yields int(2700*0.35) =
945 s, below the 1800 s MAX_EXECUTION_TIME the dataset script grants its own INSERTs, which is the
pre-emption a test in this PR now excludes. Failing fast when the reserve is short fires at elapsed
8940 s, where 9060 s still remain against a worst observed healthy prep of 1010 s, so it would red
a job with 9x the time it needs. In the window itself the shipped bound merely fires no earlier than
the watchdog, which is master's behaviour today, so nothing regresses.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
CI finish ledger - fc266f5CI is fully finished on this head: 173 unique check-runs, none queued or in progress, No failures, so there is nothing to own. 53 OK, 119 correctly skipped; CIDB holds 0 The bugfix validation actually ran rather than being skipped: Session id: cron:our-pr-ci-monitor:20260820-150000 |
7e5c64b
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Found triaging #115351, whose
Stateless tests (amd_tsan, flaky check)burned its full 9000 s budget with no test result at all. No related open issue.
What breaks.
prepare_stateful_dataoccasionally wedges on oneclickhouse-clientstatement,then sits silent until praktika's watchdog kills the job:
clickhouse-testnever starts, CIDB getsonly a job-level
errorrow with an emptytest_name, and the server logs are lost, since a killedjob never reaches
COLLECT_LOGS. Five occurrences in 60 days, allamd_tsan.Root cause. The prep script runs as one unbounded
Shell.run. Underset -eplus an ERR trap astatement that fails is named and aborts the step, but one that never returns is no error at all:
nothing fires, and
Shell.runblocks inproc.wait()until the watchdog.The change. Each prep statement is prefixed with
timeout --verbose --signal=TERM --kill-after=60 N. A bound reached exits 124 (137 after the kill),which
set -eand the existing trap turn into a line naming the statement, and the job fails fastso log collection preserves the server logs.
Nis derived from the job budget (35 %, so 3150 s).Per statement rather than one wrapper: against a client ignoring SIGTERM,
--kill-afterdelivers anuncatchable SIGKILL, and only a per-statement bound leaves the trap alive to name it.
Shell.run(timeout=)fails likewise, SIGTERMing the process group with no exit code and no stderr.Both contrasts are asserted in
ci/tests/test_stateful_prep_bounded.py, as is the local-run path.This does not fix the hang, whose cause is unknown; it produces the evidence to find it.
Complementary to #109745, which skips most of this block on
--no-statefuljobs: that decideswhether statements run, this bounds each that does, and the flaky check is not such a job.
terminate()'s log flush is unbounded too, but no CIDB row in 90 days implicates it.Sizing of the bound, and validation
3150 s is 3.1x the worst prep wall-clock observed over 30 healthy job logs across 7 flavours
(1010 s; worst
amd_tsan671 s) and above the script's own 1800 smax_execution_time, so itcannot pre-empt a legitimate INSERT. The five recorded hangs were each silent for 8414 s or
more, so the two populations do not overlap. Both limits are read from the production configs
and asserted for all 61 jobs that run
functional_tests.py, so a retuned budget cannotsilently push the bound under a legitimate INSERT or past the room log collection needs.
ci/tests/test_stateful_prep_bounded.pyci/tests/suitetest_max_failures_exit_code.py, identical on unmodified master)ruff checkrepo-widebash -nclean, 24 bounded statements eachBoth directions, end to end with a stub client that hangs on one statement:
A TERM-ignoring statement gives exit 137 and is still named;
Shell.run(timeout=)gives neitherline.
Workflow [PR]
Sync PR [sync-upstream/pr/115585]
Version info
26.9.1.300(included in26.9and later)