Skip to content

Add timeout to 02889_file_log_save_errors polling loop - #101367

Merged
alexey-milovidov merged 10 commits into
ClickHouse:masterfrom
groeneai:fix/02889-file-log-save-errors-timeout
Jun 26, 2026
Merged

alexey-milovidov merged 10 commits into
ClickHouse:masterfrom
groeneai:fix/02889-file-log-save-errors-timeout

Conversation

@groeneai

@groeneai groeneai commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #101334

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

02889_file_log_save_errors waited on a background materialized view fed by the FileLog directory watcher. Under the 50x parallel flaky check on sanitizer builds, BackgroundSchedulePool contention delayed the watcher past the 120s wait, so the test exceeded the flaky-check 180s per-test gate and was reported as a failure. This is the same scheduling dependency that makes the sibling FileLog->MV tests (02968, 02026, 04031, 04242, 04257) use no-parallel.

The materialized view and polling loop are replaced with a single synchronous direct SELECT from the FileLog table (stream_like_engine_allow_direct_select). One read consumes every file at once, so there is no watcher thread to wait on: the test runs in ~1s and no longer depends on pool scheduling, making it parallel-safe without a no-parallel tag. Output and the reference file are unchanged.

Verified locally (snapshot debug binary): --test-runs 50 with full randomization is 50/50 OK at ~1.2s each; injecting an extra error makes the final SELECT differ from the reference, so the test still fails fast on a real regression.

Version info

  • Merged into: 26.7.1.124

@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR Validation Gate (Session cron:clickhouse-ci-task-worker:20260331-111500)

a) Deterministic repro? The failure is a timeout — the test hangs indefinitely when the FileLog background thread is delayed. The infinite loop IS the bug (no timeout = guaranteed hang under slow conditions). Under normal conditions, the test completes in ~2.8s, but TSAN overhead (20x) can push this beyond CI's test timeout.

b) Root cause explained? The while true; do sleep 1; done loop waits for count() == 20 with no exit condition other than success. The FileLog engine's background thread (StorageFileLog::threadFunc) processes data asynchronously. Under TSAN/MSAN, the thread pool scheduling delay + data processing time + exponential backoff in DirectoryWatcherBase (500ms → 1s → 2s → ... → 32s) can compound beyond the CI test timeout (300s). The loop has no way to detect this and fail cleanly.

c) Fix matches root cause? Yes — adding a 120-second timeout directly addresses the unbounded wait. The timeout is generous enough for TSAN (test completes in ~2.8s on debug, so even 40x overhead = 112s fits within 120s). If the timeout IS reached, it means a real engine issue, and the error message makes diagnosis straightforward.

d) Test intent preserved? The test still verifies that FileLog with handle_error_mode='stream' correctly captures 20 parse errors into the Materialized View and outputs them in the correct order. Only the polling mechanism gets a timeout.

e) Both directions demonstrated? ✅ Without fix: the test hangs indefinitely under slow conditions (demonstrated by the CI failures in CIDB). With fix: 50/50 passes with full randomization locally.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @antaljanosbenjamin — could you review this? It adds a 120-second timeout to the FileLog test's polling loop to prevent infinite hangs under TSAN/MSAN overhead, following the same pattern from 02968_file_log_multiple_read.sh.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Mar 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5c3f9c5]

Summary: ✅


AI Review

Summary

This PR replaces the flaky asynchronous FileLog to materialized-view polling in 02889_file_log_save_errors with a synchronous direct FileLog read using stream_like_engine_allow_direct_select, then stores the same streamed parse-error fields into log_errors. The current diff addresses the earlier timeout/equality review points by removing the polling loop entirely, and I found no new correctness issues worth blocking on.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Mar 31, 2026
@antaljanosbenjamin

Copy link
Copy Markdown
Member

@groeneai this doesn't actually fixes the issue, just turns it into a different error. Maybe let's reduce the number of errors.

groeneai and others added 2 commits March 31, 2026 17:16
The test had an infinite `while true; do sleep 1; done` loop waiting for
exactly 20 error records from a FileLog → Materialized View pipeline.
Under TSAN/MSAN builds or resource-constrained Fast test runners, the
FileLog background thread can be significantly delayed, causing the test
to hang until the CI runner kills it after the test timeout.

Replace the unbounded loop with a 120-second timeout, following the same
pattern used in 02968_file_log_multiple_read.sh. The test data is tiny
(40 records total), so 120 seconds provides generous headroom even under
heavy sanitizer overhead. On failure, the timeout now produces a clear
error message and properly cleans up tables and files.

Closes ClickHouse#101334

Co-Authored-By: Claude Opus 4.6 <[email protected]>
As suggested by @antaljanosbenjamin: the timeout approach just turns
the hang into a different error. Reducing the error count (3 per file
instead of 10) addresses the actual issue — less data for the FileLog
background thread to process under TSAN/MSAN overhead.

The test still exercises: multi-file reading, error capture with
handle_error_mode='stream', MV error routing, and correct output
ordering. The timeout is kept as a safety net.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@groeneai
groeneai force-pushed the fix/02889-file-log-save-errors-timeout branch from 174b221 to 4d0607e Compare March 31, 2026 17:29
@groeneai

Copy link
Copy Markdown
Collaborator Author

@antaljanosbenjamin Good point — reduced the error count from 20 to 6 (3 per file instead of 10). The FileLog background thread now has 70% less data to process, which should complete well within TSAN overhead limits. The test still covers multi-file reading, error capture via handle_error_mode='stream', MV routing, and output ordering.

Kept the 120s timeout as a safety net in case of future engine regressions, but the primary fix is the data reduction as you suggested.

50/50 passes locally with full randomization (avg 2.8s per run).

@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@groeneai

groeneai commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

Done — merged latest master (includes the SimSIMD SVE MSan fix from #101239) into the branch. CI should re-run with the fix included.

pull Bot pushed a commit to AKJUS/ClickHouse that referenced this pull request Apr 29, 2026
The test polled `table_to_store_data` for FileLog → MaterializedView ingest
with a 30-second deadline. FileLog uses exponential backoff to watch the
directory (initial 500ms, max 32s — `poll_directory_watch_events_backoff_max`),
so the worst-case poll interval is bigger than the test's wait window.
Under sanitizer builds and shared CI runners, the backoff occasionally drifts
close to that upper bound, the test fires its `wait_for_row_count` timeout
before `StorageFileLog::threadFunc` runs, and the test fails.

Failure data (CIDB, 30 days): 11 hits across 4 unrelated PRs, 0 master.
The arm_asan_ubsan, targeted shard had a single CI run with 7 concurrent
parallel-test instances all hitting the timeout (test duration 38s, just over
30s) which matches the polling-backoff hypothesis exactly.

Deterministic local repro: forcing
`poll_directory_watch_events_backoff_init = 31000` (>30s) makes the
current 30s timeout fail every time and the new 120s timeout pass with
89s of headroom.

Same fix pattern as PR ClickHouse#101367 (`02889_file_log_save_errors`).

Verified locally: 50/50 passes with full CI randomization (debug build).

Closes ClickHouse#79788
alexey-milovidov and others added 3 commits May 16, 2026 05:13
The 120s ceiling was too tight: the arm_asan_ubsan flaky check explores
many randomized settings, and a single combination pushed the FileLog
background pipeline past 120s while the other ~50 runs finished in ~14s.
The bounded timeout still prevents the original infinite hang; 300s
just gives the worst-case randomization room to complete.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101367&sha=ecaa39e85888302e6059c6f2f300cbbe3700c815&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20flaky%20check%29
The wait loop used exact equality (`!= 6`), so if the FileLog background
thread ever produced more than 6 error records (e.g. duplicate read or
retry), the loop could only exit via the 300s timeout — turning a clean
reference-comparison mismatch into a slow, opaque timeout.

Switch to a lower-bound check (`-lt 6`): the loop exits as soon as we
have at least 6 records, and any overshoot is then caught immediately by
the final `SELECT ... FROM log_errors ORDER BY file, record` against
the reference file. Failures become fast and diagnostic instead of slow.

Addresses the bot review on PR ClickHouse#101367.

Verified locally: 50/50 pass with the unchanged data layout (1-2s each),
and an artificial 7-error overshoot now fails the reference comparison
in 1s instead of timing out at 300s.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Addressed the bot's lower-bound suggestion: switched the polling loop from [[ $(count) != 6 ]] to [[ $(count) -lt 6 ]] so an overshoot in log_errors (e.g. a duplicate read by the FileLog background thread) fails fast on the final reference comparison instead of spinning until the 300s timeout.

Verified locally with port 19006 against a fresh Debug build:

  • Normal path: 50/50 passes, 1–2s each (matches expected ~14s normal CI runtime).
  • Overshoot path: wrote 7 errors instead of 6; the new -lt 6 loop exits at count=6 in 1s, then the final SELECT * FROM log_errors ORDER BY file, record produces 7 rows and fails the reference comparison immediately — exactly the fast/diagnostic behavior the bot asked for.

Commit: 84f19e4.

@antaljanosbenjamin / @Algunenano — would either of you have a moment to re-look at this? The PR has been stalled since the data-reduction commit on March 31; CI now shows the test is stable on master (issue #101334 was auto-closed by @alexey-milovidov on May 1 after 14 stable days), but this leftover flaky check arm_asan_ubsan run still benefits from the change and the bot review on top of @alexey-milovidov's recent 300s timeout bump.

…save-errors-timeout

Refresh the branch against current master to re-run CI. The last CI run
was on 2026-05-16; the branch was ~1 month behind. master did not touch
`02889_file_log_save_errors.sh` or its reference, so the PR's changes are
preserved byte-identical. The sole remaining CI failure was the
master-wide `Cannot start clickhouse-server` infrastructure flake.
groeneai and others added 2 commits June 18, 2026 14:10
… gate

The 300s internal timeout was dead code in flaky-check mode: tests/clickhouse-test
fails any non-`long` test once total time exceeds TEST_MAX_RUN_TIME_IN_SECONDS
(180s), so the harness kills the run before the 300s ceiling can ever fire.

Fix the root cause instead of the ceiling: cap
poll_directory_watch_events_backoff_max=1000 on the FileLog table (default is
32000), mirroring the sibling 02968_file_log_multiple_read.sh. This bounds the
directory-watcher backoff to ~1s so detection stays fast even under sanitizer
and parallel load, and lowers TIMEOUT back to 120s (now realistic, under the
180s gate). Test completes in ~2s locally; 15/15 pass with randomization.

Addresses the clickhouse-gh[bot] review on PR ClickHouse#101367.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The test waited on a background materialized view fed by the FileLog
directory watcher. Under the 50x parallel flaky check on sanitizer builds,
BackgroundSchedulePool contention delayed the watcher past the 120s wait,
so the test hit the flaky-check 180s per-test gate and was reported as a
failure.

Replace the materialized view and polling loop with a single synchronous
direct SELECT from the FileLog table (stream_like_engine_allow_direct_select).
One read consumes every file at once, so there is no watcher thread to wait
on: the test runs in ~1s and no longer depends on pool scheduling, making it
parallel-safe without a no-parallel tag. Output is unchanged.

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (commit 5c3f9c5)

# Question Answer
a Deterministic repro? Yes. The 3/50 amd_asan_ubsan, flaky check failures on the prior commit all hit the internal 120s wait (test_duration_ms ~140s). Cause is BackgroundSchedulePool starvation: under 50x parallel asan load the FileLog watcher task can't be scheduled within 120s, so the MV never receives the 6 error rows.
b Root cause explained? The test waited on a background materialized view fed by the FileLog directory watcher. The watcher runs on BackgroundSchedulePool; under 50x concurrent sanitizer instances the pool is saturated, the watcher is starved, the rows never arrive in time, the wait times out, exit 1 produces an output mismatch. Capping the watcher backoff (prior commit) does not help because the task is never scheduled, not merely backing off.
c Fix matches root cause? Yes. Removing the watcher dependency removes the cause: a single synchronous direct SELECT (stream_like_engine_allow_direct_select) reads every file at once in the foreground, so there is no background task to be starved and nothing to wait on.
d Test intent preserved / new tests added? Preserved. The test still verifies FileLog handle_error_mode='stream' routes parse errors to _error/_raw_record/_filename and produces exactly the 6-row reference output. .reference is unchanged.
e Both directions demonstrated? Yes. --test-runs 50 with full randomization: 50/50 OK at ~1.2s each (was timing out). Injecting a 7th error makes the final SELECT output differ from .reference, so the test fails fast on a real regression.
f Fix is general, not a narrow patch? N/A (test-only change; no source code modified). The synchronous-read pattern matches the established FileLog test idiom (stream_like_engine_allow_direct_select is already used by 02022/02023/02025/02026/03381).

Session id: cron:clickhouse-worker-slot-0:20260618-154100

@clickhouse-gh

clickhouse-gh Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.20% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.40% 77.40% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 415 line(s), 15 function(s) across 139 file(s) · Details

Top files
  • src/Storages/StorageReplicatedMergeTree.cpp: 42 line(s), 1 function(s)
  • src/Processors/Formats/Impl/Parquet/Decoding.cpp: 18 line(s)
  • src/Databases/DatabaseFactory.cpp: 11 line(s)
  • src/Functions/FunctionsNumericIndexedVector.h: 10 line(s)
  • src/Common/ZooKeeper/ZooKeeper.cpp: 8 line(s), 2 function(s)

Full report

@alexey-milovidov alexey-milovidov self-assigned this Jun 26, 2026
@alexey-milovidov
alexey-milovidov merged commit 4daa6a9 into ClickHouse:master Jun 26, 2026
165 of 166 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 26, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The wait loop used exact equality (`!= 6`), so if the FileLog background
thread ever produced more than 6 error records (e.g. duplicate read or
retry), the loop could only exit via the 300s timeout — turning a clean
reference-comparison mismatch into a slow, opaque timeout.

Switch to a lower-bound check (`-lt 6`): the loop exits as soon as we
have at least 6 records, and any overshoot is then caught immediately by
the final `SELECT ... FROM log_errors ORDER BY file, record` against
the reference file. Failures become fast and diagnostic instead of slow.

Addresses the bot review on PR ClickHouse#101367.

Verified locally: 50/50 pass with the unchanged data layout (1-2s each),
and an artificial 7-error overshoot now fails the reference comparison
in 1s instead of timing out at 300s.
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
… gate

The 300s internal timeout was dead code in flaky-check mode: tests/clickhouse-test
fails any non-`long` test once total time exceeds TEST_MAX_RUN_TIME_IN_SECONDS
(180s), so the harness kills the run before the 300s ceiling can ever fire.

Fix the root cause instead of the ceiling: cap
poll_directory_watch_events_backoff_max=1000 on the FileLog table (default is
32000), mirroring the sibling 02968_file_log_multiple_read.sh. This bounds the
directory-watcher backoff to ~1s so detection stays fast even under sanitizer
and parallel load, and lowers TIMEOUT back to 120s (now realistic, under the
180s gate). Test completes in ~2s locally; 15/15 pass with randomization.

Addresses the clickhouse-gh[bot] review on PR ClickHouse#101367.

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

Add timeout to 02889_file_log_save_errors polling loop
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 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.

5 participants