Skip to content

Bound each system-table dump with a timeout in Collect logs - #109837

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:ci-fix-dump-system-tables-timeout
Jul 10, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:ci-fix-dump-system-tables-timeout

Conversation

@groeneai

@groeneai groeneai commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

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

The "Collect logs" phase of stateless jobs dumps ~12 system tables one by one with clickhouse local ... select * from system.<table> into outfile .... On amd_tsan + s3 runs the JSON-typed system.minio_audit_logs table can grow very large and clickhouse local can hang reading it. The dump command had no per-command timeout, so a single stuck table consumed the rest of the job's 9000s budget. The job watchdog then SIGKILLed everything and the job finished with a job-level ERROR (exit code 125 / -15) and results: [] - no individual test failed.

This is the "genuine 9000s timeout" variant of Stateless tests (amd_tsan, s3 storage, parallel, 2/2) failures (distinct from the praktika watchdog exit-125 hang fixed by #109096). Signature in all three sampled failures: all tests pass (~6000s), then dump_system_tables dumps 10 tables fine and hangs on the 11th (minio_audit_logs) until the 9000s watchdog fires.

Sample failures (all end with the timeout firing during the minio_audit_logs dump):

Fix: wrap each dump in coreutils timeout --signal=TERM --kill-after=60 600 so one stuck table is bounded and reported as a failed dump (info on the "Scraping system tables" result) instead of exhausting the whole job budget. timeout returns 124 on expiry, handled by the existing res != 0 branch with a clear "timed out after Ns" message. Applied to all three replica dump call sites.

Added ci/tests/test_dump_system_tables_timeout.py covering both directions of the timeout wrapper and guarding that the production code keeps building the timeout prefix.

Version info

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

The Collect logs phase of stateless jobs dumps ~12 system tables one by one
with clickhouse local. On amd_tsan + s3 runs the JSON-typed
system.minio_audit_logs table can grow huge and clickhouse local can hang
reading it. Because the dump command had no per-command timeout, a single
stuck table consumed the rest of the job's 9000s budget; the job watchdog
then SIGKILLed everything and the job finished with a job-level ERROR
(exit code 125 / -15) and results:[] with no individual test failing.

Wrap each dump in coreutils timeout so one stuck table is bounded (600s) and
reported as a failed dump instead of exhausting the whole job budget.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. timeout --signal=TERM --kill-after=60 2 sleep 30 returns 124 in ~2s; without the wrapper sleep runs to completion. The CI signature is deterministic: three sampled failures (#107307, #103402, #103706) all hang on the 11th dump (minio_audit_logs) until the 9000s watchdog fires.
b Root cause explained? The Collect logs phase dumps ~12 system tables via clickhouse local ... into outfile. On amd_tsan+s3 the JSON-typed system.minio_audit_logs grows huge and clickhouse local hangs reading it. With no per-command timeout, the stuck dump consumes the rest of the 9000s job budget; the job watchdog SIGKILLs everything and the job errors with exit 125/-15 and results:[].
c Fix matches root cause? Yes. Wraps each dump in coreutils timeout so one stuck table is bounded (600s) and reported as a failed dump instead of exhausting the whole job budget. Directly caps the unbounded command that is the mechanism in (b).
d Test intent preserved / new tests added? Added ci/tests/test_dump_system_tables_timeout.py (4 tests): a hanging command is killed within the cap (rc 124), an unwrapped command runs unbounded, a fast command passes through, and a guard that the production code keeps building the timeout prefix. No existing test weakened.
e Both directions demonstrated? Yes. Guard test PASSES on the fixed source and FAILS on a pre-fix copy (prefix stripped). Behavioral tests show hanging→124-within-cap vs unbounded.
f Fix is general across code paths? Yes. Applied to all three replica dump call sites (run_r0 / run_r1 / run_r2).
g Fix generalizes across inputs? N/A (CI harness change, not a code bug). The cap applies to every table in the dump loop, not just minio_audit_logs.
h Backward compatible? N/A (CI harness change). No user-visible behavior, settings, or formats changed.
i Invariants and contracts preserved? Yes. timeout exits 124 on expiry, routed through the existing res != 0 failure branch (with a clear "timed out after Ns" message); a successful dump is unchanged (rc 0, same command). No change to the dump ordering or output files.

Session id: cron:clickhouse-worker-slot-6:20260708-194100

@groeneai

groeneai commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv @leshikus - could you review? This bounds each system-table dump in the Collect logs phase so one stuck table (a huge minio_audit_logs on amd_tsan+s3) cannot eat the whole 9000s job budget and get the job SIGKILLed with results:[]. Pure ci/ change: clickhouse_proc.py + a regression test.

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

clickhouse-gh Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [efaecca]

Summary: ✅


AI Review

Summary

This PR wraps each dump_system_tables invocation in timeout and extends the timeout annotation to cover the --kill-after path. The general approach is reasonable, but the current 137 handling is too broad: it will also relabel unrelated SIGKILLs as timeouts, which can hide the real failure mode during CI triage.

Findings

⚠️ Majors

  • [ci/jobs/scripts/clickhouse_proc.py:1311] _annotate_timeout treats every 137 from timeout as "the dump exceeded its cap", but timeout also returns 137 when the wrapped command is SIGKILLed for unrelated reasons. A concrete repro is timeout --signal=TERM --kill-after=1 600 sh -c 'kill -9 $$', which exits 137 almost immediately. With the current helper, an OOM-killed or externally-killed clickhouse local dump would be reported as timed out after 600s, hiding the actual failure mode.
    Suggested fix: keep unconditional timeout handling for 124, but only classify 137 as a timeout when the command actually ran long enough to hit the configured cap (for example by measuring elapsed wall-clock time around Shell.get_res_stdout_stderr), or switch to a wrapper that records when timeout had to escalate.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: stop treating every 137 as a timeout; keep the 124 handling, and gate the 137 annotation on evidence that the timeout path actually fired.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 8, 2026
Comment thread ci/jobs/scripts/clickhouse_proc.py Resolved
…bles

timeout returns 124 only when the child dies on the initial SIGTERM. A dump
that ignores SIGTERM is escalated with SIGKILL after --kill-after and exits
128+9 = 137, which previously fell through without the "timed out after ..."
annotation. Classify both 124 and 137 as timeouts via a shared
_annotate_timeout helper and apply it to all three dump branches (replica
0/1/2), which the replica 1/2 branches previously lacked entirely.

Add a TERM-ignoring regression case (trap "" TERM) that exercises the
--kill-after escalation path and asserts the 137 exit code, run through the
default shell in the same `cd ... && timeout ...` shape as production so the
137 code is surfaced rather than a raw SIGKILL.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in efaecca:

  • Both timeout expiry codes are now classified as timeouts: 124 (child dies on the initial SIGTERM) and 137 = 128+9 (a SIGTERM-ignoring child escalated with SIGKILL after --kill-after). Factored into a shared _annotate_timeout helper (_TIMEOUT_EXIT_CODES = (124, 137)).
  • The annotation is now applied to all three dump branches (replica 0/1/2); the replica 1/2 branches previously added no timeout annotation at all.
  • Added a TERM-ignoring regression case (trap "" TERM; sleep 30) that exercises the --kill-after escalation path and asserts exit 137. It runs through the default shell in the same cd ... && timeout ... shape as production, so the 137 exit code is surfaced (a bare bash -c sole command exec-replaces the shell and would surface the raw SIGKILL as -9 instead).

Verified locally with coreutils 9.4: timeout --signal=TERM --kill-after=1 1 sh -c 'trap "" TERM; sleep 30' returns 137 through the production command shape; all 5 tests in ci/tests/test_dump_system_tables_timeout.py pass and ruff is clean.

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jul 8, 2026
Comment thread ci/jobs/scripts/clickhouse_proc.py Resolved
@alexey-milovidov alexey-milovidov self-assigned this Jul 10, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 10, 2026
Merged via the queue into ClickHouse:master with commit d82fac6 Jul 10, 2026
174 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 10, 2026

@azat azat left a comment

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.

AFAICS the problem is minio logs - https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107307&sha=2817cfac2ebe798bb14a65fd758886c7048be8c5&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20parallel%2C%202%2F2%29

But why minio_audit_logs is so heavy? I think this will only hide the problem
Shouldn't we collapsed it instead?
Also why not use clickhouse builtin limit, i.e. "max_execution_time".

@groeneai

Copy link
Copy Markdown
Collaborator Author

Answers inline.

Why minio_audit_logs is heavy. It is JSON-typed (log JSON(time DateTime64(9))) fed by minio's audit_webhook, which emits one row per S3 API request. On s3-storage runs every part PUT/GET/HEAD/LIST/DELETE across the whole parallel suite becomes an audit row, so it reaches into the millions - the 20M-row ROWS_COUNT_IN_SYSTEM_TABLE_LIMIT guard exists for exactly this table. Two compounding costs: raw row count, and JSON materialization on select * ... into outfile ... TSVWithNamesAndTypes. And the dump runs with all limits disabled on purpose (LOGS_SAVER_CLIENT_OPTIONS sets --max_rows_to_read=0 --max_execution_time 0 ...), so nothing bounds it. So it is expected volume, not a bug.

Collapse vs timeout - agreed, the timeout only bounds the symptom. The volume is genuine S3 traffic, so the durable fix is to reduce what we dump, not just cap it. Options I can do as a follow-up:

  • dump an aggregate rollup of minio_audit_logs instead of raw rows (counts grouped by api / status / bucket / key-prefix), which is what triage actually reads; optionally keep the raw table but LIMITed to the most recent N.
  • or drop the raw minio_* dumps and keep only the rollup.

Which shape do you prefer? I will send the collapse PR once you pick. The timeout stays as a backstop for the wedged case below regardless.

Why not max_execution_time. It is a query-level soft cap, checked cooperatively between blocks. The failure we hit is a wedged clickhouse local (server crashed -> we read via clickhouse-local; on s3_with_keeper the disk/keeper init is a known hang, #77320), where the stall is in startup / disk init / outfile flush / shutdown, not in query execution -> max_execution_time never fires and the process eats the whole 9000s budget. timeout --signal=TERM --kill-after is a process-level hard cap that bounds the entire wall-clock unconditionally. The log saver also deliberately zeroes max_execution_time to gather complete *_log tables. So it can complement (a cheap clean CH error first) but cannot replace the hard cap; happy to add --max_execution_time <cap> as a first-line soft limit on top of the collapse if useful.

For the spurious Scraping system tables FAIL these bounded timeouts produced, #110099 (open, approved) already makes a proven bounded minio_* timeout info-only so it no longer inflates the failed-sub-result count.

pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Jul 20, 2026
A bounded 600s timeout on system.minio_audit_logs / minio_server_logs is
minio's own webhook-fed operational-log volume on s3 runs, not a ClickHouse
bug. ClickHouse#109837 bounded the dump so a stuck table no longer eats the 9000s job
budget, but it surfaced the bounded timeout as a FAIL, reddening otherwise-green
PRs. Keep the detail visible in the report but only turn the check FAIL on a
genuine failure (a real system table, a non-timeout minio error, too-many-rows,
or any replica dump failure).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-tables-timeout

Bound each system-table dump with a timeout in Collect logs
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
A bounded 600s timeout on system.minio_audit_logs / minio_server_logs is
minio's own webhook-fed operational-log volume on s3 runs, not a ClickHouse
bug. ClickHouse#109837 bounded the dump so a stuck table no longer eats the 9000s job
budget, but it surfaced the bounded timeout as a FAIL, reddening otherwise-green
PRs. Keep the detail visible in the report but only turn the check FAIL on a
genuine failure (a real system table, a non-timeout minio error, too-many-rows,
or any replica dump failure).

Co-Authored-By: Claude Opus 4.8 <[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 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