Skip to content

Bump SystemLogQueue::waitFlush timeout to 600s - #105484

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-02345-systemlog-flush-timeout-bump
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-02345-systemlog-flush-timeout-bump

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Bump the hardcoded timeout_seconds in SystemLogQueue::waitFlush from 180s to 600s.

The previous bump (60s -> 180s) is no longer sufficient on heavily loaded parallel CI runners. SYSTEM FLUSH LOGS query_log periodically throws:

Code: 159. DB::Exception: Received from localhost:9000.
DB::Exception: Timeout exceeded (180 s) while flushing system log
'DB::SystemLogQueue<DB::QueryLogElement>'. (TIMEOUT_EXCEEDED)
(query: SYSTEM FLUSH LOGS query_log;)

CIDB shows 23 master hits across 4 distinct PRs in the last 30 days for 02345_implicit_transaction alone, spanning amd_tsan parallel, amd_asan_ubsan distributed plan parallel, arm_binary parallel, amd_llvm_coverage, amd_debug parallel, arm_asan_ubsan azure, and others. The common factor is parallel runners with heavy query_log backlog, not a specific sanitizer or storage backend.

The throw is server-side from SystemLogQueue::waitFlush and is not influenced by client receive_timeout. So bumping the server-side constant is the only way to give the flush more headroom under load. Updated the comment to reflect the latest tune-up rationale.

This is the third test in the bundle requested by @rschu1ze in #104648. Companion PRs:

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):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

The hardcoded `timeout_seconds` constant in `SystemLogQueue::waitFlush`
was bumped from 60s to 180s long ago to accommodate parallel functional
tests on slow disks. Heavy parallel CI runners still hit the 180s ceiling
and produce `TIMEOUT_EXCEEDED` exceptions from `SYSTEM FLUSH LOGS`:

    Code: 159. DB::Exception: Received from localhost:9000.
    DB::Exception: Timeout exceeded (180 s) while flushing system log
    'DB::SystemLogQueue<DB::QueryLogElement>'. (TIMEOUT_EXCEEDED)
    (query: SYSTEM FLUSH LOGS query_log;)

This is the cause of recurring failures of `02345_implicit_transaction`
(and similar tests using `SYSTEM FLUSH LOGS query_log` on parallel
runners): 23 master hits across 4 distinct PRs in the last 30 days,
spanning `amd_tsan parallel`, `amd_asan_ubsan distributed plan parallel`,
`arm_binary parallel`, `amd_llvm_coverage`, `amd_debug parallel`,
`arm_asan_ubsan azure`, and others.

Bump the limit to 600s for the same reason the previous bump was made:
heavy parallel tests on slow disks can stall flush longer than 180s
without anything actually going wrong. Update the comment to reflect
the latest tune-up rationale.

This is the third test in the bundle requested by @rschu1ze in ClickHouse#104648.
Companion PRs: ClickHouse#105474 (02435) and ClickHouse#105457 (01563).
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

Session: cron:clickhouse-ci-task-worker:20260521-020000

a) Deterministic repro?

Not reproducible locally — the failure only occurs on heavily loaded parallel CI runners where multiple parallel tests saturate disk I/O. The mechanism is well understood from the previous 60s -> 180s bump (commit history of SystemLogBase.cpp) and from the existing comment that explicitly documented the parallel-load reason. Trying to reproduce with multiple shells flushing on the same instance does not match the disk contention of CI's parallel runner. The CIDB-confirmed pattern (parallel runners, mixed sanitizer / storage / planner variants, SYSTEM FLUSH LOGS query_log as the throwing query) is itself the evidence.

b) Root cause explained?

SystemLogQueue<LogElement>::waitFlush in src/Common/SystemLogBase.cpp:164 uses a hardcoded timeout_seconds = 180 to bound confirm_event.wait_for. On heavily loaded parallel runners, the background flush thread (savingThreadFunction) is bottlenecked behind disk writes and prepared_tables >= expected_flushed_index is not satisfied within 180s, so wait_for returns false and the function throws TIMEOUT_EXCEEDED. The client cannot influence this — receive_timeout is unrelated and the throw is server-side.

c) Fix matches root cause?

Yes. The root cause is that the upper bound on a bursty wait is too low for one specific deployment scenario (parallel CI), and the value is hardcoded. Raising the hardcoded value gives the wait more headroom while keeping the same "avoid endless waiting" property. The previous 60s -> 180s bump was made for exactly the same reason, by the same kind of fix. Promoting this to a server setting (option B in the worker plan) is a strictly larger change and was rejected as premature; if 600s also turns out to be insufficient, the next step is to introduce a setting.

d) Test intent preserved? / new tests?

02345_implicit_transaction already covers the behavior it cares about (implicit transactions, transaction_id column, system table interactions). The flaky surface is purely SYSTEM FLUSH LOGS query_log returning TIMEOUT_EXCEEDED before the data has been flushed. Bumping the timeout does not weaken any assertion in the test, does not pin any setting, does not skip anything. No new test is added because the underlying behavior (the wait succeeds when the flush completes, otherwise it raises an exception) is unchanged.

e) Demonstrated in both directions?

Strictly, no — the failure cannot be reliably reproduced on this hardware. What I did verify locally:

  • Source change compiles cleanly (ninja -C build clickhouse rebuilt only SystemLogBase.cpp.o plus the relinks)
  • Disassembly of SystemLogQueue<QueryLogElement>::waitFlush in the rebuilt binary contains movl $0x258,0x68(%rsp) (0x258 = 600), confirming the constant is encoded
  • Running SYSTEM FLUSH LOGS query_log against the rebuilt server completes immediately under no load
  • Test 02345 itself: lines 1-17 (the pre-Keeper segment) ran successfully under the rebuilt binary; lines after BEGIN TRANSACTION need a real Keeper which is not part of this minimal local server

f) Fix is general?

The change covers all SystemLogQueue<LogElement> template instantiations (QueryLog, PartLog, TextLog, ErrorLog, ZooKeeperLog, etc. — 14 total) because the constant lives in the shared template body. There is no symmetric path that needs the same fix elsewhere. Other SYSTEM FLUSH callers (e.g. SystemLog::flush) all dispatch into waitFlush, so they are covered by this single bump.

cc @rschu1ze @azat @alesapin

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze @azat @alesapin — could you review this?

This is the third of the three flaky-test fixes you asked for in #104648 (02345_implicit_transaction). The other two are #105474 (02435_rollback_cancelled_queries) and #105457 (01563_distributed_query_finish).

One-line server-side change to src/Common/SystemLogBase.cpp bumping the hardcoded SystemLogQueue::waitFlush timeout from 180s to 600s. CIDB shows 23 master hits across 4 distinct PRs for 02345_implicit_transaction alone over 30 days, all on parallel runners hitting TIMEOUT_EXCEEDED on SYSTEM FLUSH LOGS query_log. The previous 60s -> 180s bump was made for the same reason; raising again is consistent.

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

clickhouse-gh Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [98b907f]

Summary: ✅


AI Review

Summary

This PR changes SystemLogQueue::waitFlush to accept an explicit timeout, keeps 600 seconds for regular SYSTEM FLUSH LOGS behavior, and uses 60 seconds on the crash path. The current code resolves the previously raised crash-budget issue, and I found no remaining correctness or safety problems in the touched paths.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 21, 2026
Comment thread src/Common/SystemLogBase.cpp Resolved
`SignalHandlers.cpp` gives the fatal-signal handler a hard ~303s wall
before it re-raises the signal and lets the default handler kill the
process. `SystemLogs::handleCrash` walks every system log queue in
sequence and `crash_log` is flushed first because it carries the
diagnostics we most want on disk.

Bumping the shared `waitFlush` timeout to 600s lets a single stuck
queue (for example `query_log` under a clogged disk) eat the entire
crash budget before `crash_log` finishes draining, so the kernel
SIGKILLs the process with the diagnostics half-written.

Split the timeout: keep 600s as the default for the user-triggered
`SYSTEM FLUSH LOGS` path (which originally needed the bump for heavy
parallel CI runners), and force the crash path to 60s so each queue
fails fast and the rest of the chain still gets a fair share of the
303s budget.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks @clickhouse-gh for catching the crash-budget concern. Pushed 98b907ff30f6 to split the timeout.

waitFlush now takes an explicit int timeout_seconds = 600 parameter.

  • SystemLogBase::flush (the user-triggered SYSTEM FLUSH LOGS path the original commit was tuning for 02345_implicit_transaction) keeps the 600s default.
  • SystemLogQueue::handleCrash passes 60 explicitly so each per-queue wait fits comfortably under the ~303s signal-handler budget enforced in SignalHandlers.cpp:148-160, even when SystemLogs::handleCrash walks every queue sequentially and crash_log is flushed first.

Verified locally:

$ llvm-objdump -d --disassemble-symbols='_ZN2DB13SystemLogBaseINS_15CrashLogElementEE11handleCrashEv' build/programs/clickhouse | head
...
movl $0x3c, %ecx        # 60, crash path
jmp  ... waitFlush ...

$ llvm-objdump -d --disassemble-symbols='_ZN2DB13SystemLogBaseINS_15QueryLogElementEE5flushElb' build/programs/clickhouse | head
...
movl $0x258, %ecx       # 600, user-triggered SYSTEM FLUSH LOGS
jmp  ... waitFlush ...

Only two call sites in the codebase, both updated. PTAL.

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

@groeneai This not the proper way to address this problem. Bumping the flush times won't fix the problems, and will only need to more unrelated timeouts. If we need to optimize the process (like we've done several times in the past) then we need to profile and optimize

@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 50.00% (2/4) | lost baseline coverage: 1 line(s) · Uncovered code

Full report · Diff report

UnamedRus pushed a commit to UnamedRus/ClickHouse that referenced this pull request Sep 12, 2026
Stateless jobs on amd_llvm_coverage lose whole runs to
`Timeout exceeded (180 s) while flushing system log
'DB::SystemLogQueue<DB::TraceLogElement>'`. Six different tests died on this
signature inside a single coverage job run on 2026-09-05, so it is a job-wide
trace_log drain stall rather than a property of any one test.

trace_log.symbolize defaults to true, and in-flush symbolization
(SymbolIndex::findSymbol + tryDemangle + AddressToLineCache::get, per frame in
TraceLogElement::appendToBlock) is what the single flusher thread spends the
hardcoded 180 s of SystemLogQueue::waitFlush on. ClickHouse#100242 already fixed that by
shipping tests/config/config.d/trace_log_no_symbolize.xml, but its gate probes
CXX_FLAGS LIKE '%-DSANITIZER%' and the else arm removes the file again. A
coverage build is configured -DSANITIZE= ... -DWITH_COVERAGE=ON, so it carries
no -DSANITIZER: coverage was the one stateless flavour left symbolizing at full
cost.

Probe the dedicated WITH_COVERAGE row of system.build_options instead. Plain
-DWITH_COVERAGE never reaches CXX_FLAGS (cmake/sanitize.cmake adds it only
under WITH_COVERAGE_DEPTH; the coverage compile flags are applied
per-directory), which is why build_option_flag cannot be reused and why
tests/clickhouse-test keys off the same row. The new helper keeps the
fail-closed contract of its neighbour: a renamed or missing row aborts the
install rather than reading as "not a coverage build", and every probe is
resolved before any file is touched, so a failing probe cannot leave a
half-adjusted config directory.

Measured on a debug build, a fresh server per arm (AddressToLineCache is a
process-wide static, so a warmed process understates the cost) and an identical
workload, timing the first SYSTEM FLUSH LOGS trace_log: 0.35 s with
symbolize=false, 0 of 13226 rows symbolized, versus 3.12 s with symbolize=true,
13388 of 13388 symbolized. That is 8.9x, i.e. symbolization is ~89% of flush
cost; ClickHouse#100242 measured up to 2.5 minutes for ~180k entries on an instrumented
build. This removes the dominant per-row cost without making the 180 s budget
unconditional, and deliberately does not touch that constant: raising it is the
shape ClickHouse#105484 was closed for.

The tests that assert a non-empty symbols or lines column
(03150_trace_log_add_build_id, 03150_trace_log_source_lines) already carry
no-llvm-coverage, and 00974_query_profiler resolves symbols on read, so nothing
regresses; the comments naming the affected flavours are updated to match.

One consumer did not resolve on read: the MemoryAllocatedWithoutCheck advisory
in tests/clickhouse-test suggests a diagnostic query grouped by the symbols
column. Those rows reach trace_log through MemoryTracker -> TraceSender ->
TraceCollector, which stamps every row with the config's symbolize value, so
the suggested query has collapsed every stack into a single empty bucket on all
sanitizer builds since 2026-05-08. It now resolves symbols on read with
addressToSymbol, which repairs the guidance for both flavours.

Co-Authored-By: Claude Opus 5 <[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 pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants