Skip to content

Fix 04105_system_pause_view and 04319_system_stop_all_background hanging when a poll misses the refresh - #125034

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-04105-pause-view-poll-hang
Oct 17, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-04105-pause-view-poll-hang

Conversation

@groeneai

@groeneai groeneai commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #122921

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

Fix a rare 600 s timeout of the tests 04105_system_pause_view and 04319_system_stop_all_background.

Description

Failing run on master: Stateless tests (amd_msan, parallel, 3/3), Timeout! inside wait_status p Running.

Test 1 starts a ~2 s refresh (2 rows * sleepEachRow(1)) and then polls for Running, which lasts only as long as that refresh. In the failing job the one poll issued during the refresh stalled 2.4 s on the server and read Scheduled; after that the status stays Scheduled (next refresh in 1 year), so the loop never ended and SYSTEM PAUSE VIEW was never sent. In three green msan runs the pause landed only 62-310 ms before the refresh ended.

Now the test starts the refresh, then pauses from a second client and reads status = 'Running' and (select count() from p) = 0 in the same call. Running means the refresh started before the pause, and an empty p means it had not swapped in its result yet. Otherwise it recreates the view, up to 10 times, and prints the outcome into the reference, so a slow server costs a retry or a clear mismatch, never a hang. 04319_system_stop_all_background has the same Test 1 and gets the same change. Tests 2/3 wait on 10 s refreshes and are unchanged.

Validation on a debug build:

  • sleep 3 before the old poll: Timeout! 4/4 per test, no pause sent.
  • sleep 3 in the first attempt: OK after 2 attempts, 4/4 per test.
  • sleep 3 in every attempt: fails in 39 s on the new reference line, no hang.
  • SYSTEM STOP VIEW instead of PAUSE: fails.
  • 50/50 OK per test with random settings and -j 8, 1 attempt each; the status read ended at least 1.85 s before the refresh did.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/125034]

Version info

  • Merged into: 26.11.1.132-master (included in 26.11 and later)

…refresh

Test 1 of both tests started a ~2 s refresh (2 rows * sleepEachRow(1),
refresh every 1 year) and then polled for the transient `Running` state.
When a poll stalls longer than the refresh (seen on master: one poll took
2.4 s on a loaded msan server and read `Scheduled`), the status stays
`Scheduled` until the next refresh in a year, so the loop spins until the
600 s test timeout and SYSTEM PAUSE is never sent. Even passing msan runs
paused only 62-310 ms before the refresh ended.

Now the refresh is started in one client call and the pause is sent from a
second one, which in the same call reads
`status = 'Running' and (select count() from p) = 0`. `Running` after the
pause means the refresh started before it (a paused view starts no new
refresh), and an empty `p` means the replace-mode refresh had not swapped
in its result yet. Otherwise the view is recreated and the step retried, at
most 10 times; the result goes into the reference, so a slow server costs a
retry or a labelled mismatch instead of a hang.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 Tests 2/3 still poll Running and read_rows > 0 without a bound Noted, not blocking Their refresh lasts 10 s (4x the observed 2.4 s stall), 0 failures since the 10-row change; a retry there would weaken the STOP check.

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-9:20261010-041800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. sleep 3 before wait_status p Running (the observed stalled poll was 2.4 s) makes the unfixed tests time out 4/4 each, with no SYSTEM PAUSE sent.
b Root cause explained? The refresh (~2 s) is shorter than one poll can take on a stalled server. The poll then reads Scheduled, Running never returns (next refresh in 1 year), and the loop has no exit.
c Fix matches root cause? Yes. The poll on a transient state is removed; the pause is sent right after the refresh starts, its landing during the refresh is checked, and a miss retries with a new view (at most 10). No bound widened, no tag added, still 2 rows.
d Test intent preserved / new tests added? Yes. Test 1 still checks that PAUSE lets the running refresh complete, and now also proves the pause landed during the refresh. Replacing PAUSE with STOP fails the test.
e Both directions demonstrated? Yes. Unfixed + delay: Timeout! 4/4 per test. Fixed + delay in the first attempt: OK 4/4 per test (2 attempts). Delay in every attempt: fails in 39 s on the new reference line.
f Fix is general across code paths? Yes. The identical Test 1 in 04319_system_stop_all_background gets the same change; the other waits are on terminal states or 10 s refreshes.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only change). 50/50 OK per test with random settings and -j 8.
h Backward compatible? (maintainer-approved exception only) N/A (test-only change).
i Invariants and contracts preserved? Yes. The rest of both tests is unchanged and sees the same p and src; p is dropped before each re-create.

Session id: cron:clickhouse-impl-slot-40:20261010-033500

@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3d7d12d]

Summary: ✅


AI Review

Summary

This PR replaces the unbounded wait_status ... Running polling in test 1 of tests/queries/0_stateless/04105_system_pause_view.sh and tests/queries/0_stateless/04319_system_stop_all_background.sh with a bounded retry that re-creates the view and checks that PAUSE landed while the refresh was still running. That changes the failure mode from a rare 600 s hang into a fast, labeled test failure, which matches the PR’s stated contract. I do not see a remaining correctness or reliability issue in the changed logic, and the current PR CI is green.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 10, 2026
@groeneai
groeneai requested a review from tuanpach October 10, 2026 04:36
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - b1e1e82

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05210_lightweight_update_materialized_cte_in_ignore flaky, not from this PR (which changes only the 04105 and 04319 refreshable view tests): a MATERIALIZED CTE read twice in an IN subquery fails on the replicas with UNKNOWN_TABLE for its _materialized_cte_c_* table. 106/106 reruns passed; 54 PRs show it since 2026-10-08 #123121 (mine, open)
Mergeable Check, PR praktika rollups of the row above, no independent failure #123121 (mine, open)

Session id: cron:our-pr-ci-monitor:20261010-073010

@tuanpach tuanpach self-assigned this Oct 12, 2026
@tuanpach

Copy link
Copy Markdown
Member

@groeneai merge master into this PR

@groeneai

Copy link
Copy Markdown
Collaborator Author

Merged master in 3d7d12d (clean merge, the PR's own change is unchanged).

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 17, 2026
Merged via the queue into ClickHouse:master with commit 9bc0c38 Oct 17, 2026
173 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 Oct 17, 2026
valerypetrov pushed a commit to valerypetrov/ClickHouse that referenced this pull request Oct 28, 2026
… STOP lands after the refresh

The STOP/CANCEL tests relied on a 10-row x 1 s refresh outlasting the client
start-ups between "the refresh started" and "the interrupting statement reaches
the server": a poll client (wait_running_with_progress) and then a separate STOP
client, plus a third PAUSE client in 3a. Nothing proved the refresh was still
running when STOP was processed, so on a slow sanitizer host the refresh could
finish first and the assertion read the completed state (`10 0` instead of `0 1`).

Put the "still running" check and the interrupting statements in ONE client call,
the shape ClickHouse#125034 used for Test 1: `status = 'Running' and read_rows between 1 and 8`
(read_rows runs one row ahead of the 1 s transform, so <= 8 leaves ~2 s), followed
on the same connection by STOP / PAUSE+STOP / CANCEL. If a slow server let the
refresh get past row 8 before the check, the view is re-created and the attempt
repeated (at most 10). The check result is printed as a new label line, so an
environment where every attempt misses is a labelled mismatch rather than a silent
pass, and a STOP that stops interrupting still fails the existing `0 1` line.

wait_running_with_progress becomes unused and is removed from both files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Blargian pushed a commit to Blargian/ClickHouse that referenced this pull request Nov 3, 2026
… the database disk on object storage

`interrupt_running_refresh` checks `status = 'Running' and read_rows between 1 and 8` one client
start-up after `SYSTEM REFRESH VIEW`. The refresh is already `Running` while it creates its target
table, and with the database disk on object storage that takes seconds, so the check saw
`read_rows = 0` and printed 0. Re-creating the view repeated the same timing, so all 10 attempts
missed: `<3a: refresh running before stop: 0>` in `Stateless tests (amd_asan_ubsan, db disk,
distributed plan, targeted)` (reported on ClickHouse#92472; there the check ran 0.4-0.6 s after the refresh
started and the refresh INSERT 0.6-2.6 s after it).

Wait until the refresh has read its first row, or failed, before the one-call check. A new view's
`read_rows` keeps its value after the refresh, so the wait cannot miss it (no hang like the one
ClickHouse#125034 fixed), and `clickhouse_test_time_left` bounds it. The `read_rows <= 8` check, the one-call
statements and the retry from ClickHouse#127917 are unchanged, so a STOP that lands after the refresh is
still retried and an all-miss is still a labelled mismatch.

Validated on master 4944813 CI builds: with the database disk on MinIO and 10 ms injected
latency each way, before 14/14 FAIL (release and asan_ubsan), after 56/56 and 42/42 OK, one attempt
per helper call; a failpoint that holds the refresh before it reads fails before and passes after;
50/50 OK per test with random settings on a local disk and on the database disk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-refreshable-materialized-view Refreshable materialized views: scheduled/periodic refresh, refresh state machine, refresh orches... and removed comp-testing Test content only (no production code). labels Nov 22, 2026
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 comp-refreshable-materialized-view Refreshable materialized views: scheduled/periodic refresh, refresh state machine, refresh orches... groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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