Skip to content

Fix flaky test_shutdown_cancels_backup and test_long_disconnection_stops_backup - #108459

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-fix-backup-cluster-flaky-allow-errors
Jun 27, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-fix-backup-cluster-flaky-allow-errors

Conversation

@groeneai

@groeneai groeneai commented Jun 25, 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

Fixes two flaky modes in test_backup_restore_on_cluster/test_cancel_backup.py. Both trip NoTrashChecker.__exit__ (the "no unexpected errors" assertion) when a transient ZooKeeper/network error lands inside the checker's error-collection window. PR-only flaky, master clean.

test_shutdown_cancels_backup: it restarts a node mid-backup, so the surviving node briefly loses its connection to the restarting peer and to Keeper, producing KEEPER_EXCEPTION/NETWORK_ERROR. The test declared no allow_errors, so the checker asserted. Now allows the same transient-error family the sibling disconnection tests already allow. The expect_errors=["QUERY_WAS_CANCELLED"] requirement is unchanged.

test_long_disconnection_stops_backup: allow_errors was set only near the end of the body. When the body raised earlier (e.g. a transient SOCKET_TIMEOUT during the BACKUP setup), __exit__ ran with still-empty lists and masked the real exception with a spurious assertion. The relaxations are now set immediately after entering NoTrashChecker.

Also drains backups left running by a previous test before creating the NoTrashChecker in all four affected tests (tests run in random order in CI), via a shared wait_for_backups_to_finish() helper that replaces the drain blocks previously duplicated inline in the two short-disconnection tests.

Related to #89286 (engine-side cancellation-ordering change, ZooKeeperImpl.cpp); this PR is the orthogonal test-side hardening.

Version info

  • Merged into: 26.7.1.137

…ops_backup

Both tests trip NoTrashChecker.__exit__ when a transient ZooKeeper/network
error lands in the checker's error-collection window:

- test_shutdown_cancels_backup restarts a node mid-backup; the surviving node
  briefly loses its connection to the restarting peer and to Keeper, so
  KEEPER_EXCEPTION/NETWORK_ERROR can appear. The test declared no allow_errors,
  so the checker failed. Allow the same transient-error family the sibling
  disconnection tests already allow.

- test_long_disconnection_stops_backup populated allow_errors only near the end
  of the body. When the body raised earlier (e.g. a transient SOCKET_TIMEOUT
  during the BACKUP setup), __exit__ ran with empty lists and masked the real
  failure with a spurious assertion. Move the relaxations to right after
  entering NoTrashChecker.

Also drain backups from a previous test before creating the NoTrashChecker in
all four affected tests (tests run in random order), via a shared helper that
replaces the inline blocks duplicated in the two short-disconnection tests.

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? No deterministic single-run repro — this is a rare, ZooKeeper-timing-dependent race (CIDB: ~2 hits/test/30d, 0 on master), clustered on the Keeper-overhaul PRs (#101757, #100778). Single runs pass. This is the same class for which the maintainer hardened the sibling test_short_disconnection_doesnt_stop_* tests (commit f58c554) without a deterministic repro. Root cause is established from the exact __exit__ assertion signatures in CIDB.
b Root cause explained? Yes. NoTrashChecker.__exit__ (line 375) asserts every error seen in system.errors since __init__ is in expect_errors/allow_errors. (1) test_shutdown_cancels_backup: restarting a node mid-backup makes the surviving node briefly lose its connection to the peer/Keeper → NETWORK_ERROR/KEEPER_EXCEPTION; the test set no allow_errors → assert trips (CIDB: 'NETWORK_ERROR' in ['QUERY_WAS_CANCELLED'] or ... in []). (2) test_long_disconnection_stops_backup: allow_errors was set late in the body; when the body raised earlier (transient SOCKET_TIMEOUT), __exit__ ran with both lists empty and masked the real exception (CIDB: 'SOCKET_TIMEOUT' in [] or ... in []).
c Fix matches root cause? Yes. (1) sets allow_errors for the transient family BEFORE the restart that produces them; (2) moves the relaxations to right after entering NoTrashChecker so they are always set before any body statement can raise. Both directly address the mechanism in (b). The shared drain helper removes residual errors from a prior (random-order) test's backup.
d Test intent preserved / new tests added? Yes. No requirement is removed: expect_errors=["QUERY_WAS_CANCELLED"] (shutdown) and the "Lost connection" / timing asserts (long-disconnection) are unchanged. Only ADD tolerance for transient ZK/network errors — the same family the sibling tests already allow. These are test fixes; no new test needed.
e Both directions demonstrated? Partial. The genuine race is not deterministically reproducible on a healthy single box (same as when the siblings were hardened). Confirmed the fix does NOT break the happy path: all 4 affected tests pass x1 (93.9s) and x3 in random order (12/12 passed). The relaxation only widens the allowed-error set the failing runs needed, exactly matching the CIDB signatures.
f Fix is general across code paths? Yes (test-side). The same NoTrashChecker-window race affects all four tests in this file; the drain guard is applied to all four via one shared helper, and the two siblings already had the late-relaxation issue resolved upstream. No C++ code changed.
g Fix generalizes across inputs? N/A (test-only flaky fix, no code bug).
h Backward compatible? N/A (test-only change, no settings/format/behavior change).
i Invariants and contracts preserved? Yes. NoTrashChecker's contract (no unexpected znodes/backups/errors) is unchanged; the fix only declares which transient errors are expected for each scenario, and ensures the declaration happens before the body can raise. expect_backups/check_zookeeper semantics unchanged.

Session id: cron:clickhouse-worker-slot-3:20260625-102900

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @vitlibar — could you review this test-only fix? It widens the NoTrashChecker allowed-error set for test_shutdown_cancels_backup (node restart yields transient KEEPER/NETWORK errors) and moves the relaxations earlier in test_long_disconnection_stops_backup (so an early SOCKET_TIMEOUT no longer masks the real exception), plus a shared pre-test backup drain. Same hardening pattern already applied to the sibling short-disconnection tests.

@vitlibar vitlibar self-assigned this Jun 25, 2026
@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1649377]

Summary: ✅


AI Review

Summary

This PR is a test-only hardening for test_cancel_backup.py: it factors out the pre-test backup-process drain, applies it to the affected backup-disconnection/shutdown tests, and sets the expected transient error allowances before the windows where those errors can appear. I did not find a correctness issue in the changed test logic; the CI Fix or Improvement metadata matches the change, and the current Praktika PR report shows no failed jobs.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.40% -0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.70% 77.60% -0.10%

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

Newly covered by added/modified tests: 851 line(s), 77 function(s) across 137 file(s) · Details

Top files
  • src/Server/ACME/Client.cpp: 175 line(s), 8 function(s)
  • src/Server/ACME/API.cpp: 160 line(s), 15 function(s)
  • src/Common/OpenSSLHelpers.cpp: 52 line(s), 2 function(s)
  • src/Common/Crypto/KeyPair.cpp: 28 line(s), 5 function(s)
  • src/Backups/BackupEntriesCollector.cpp: 24 line(s), 2 function(s)

Full report

@alexey-milovidov alexey-milovidov 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.

Sounds reasonable.

@alexey-milovidov alexey-milovidov self-assigned this Jun 27, 2026
@alexey-milovidov
alexey-milovidov merged commit 4e6beef into ClickHouse:master Jun 27, 2026
166 of 167 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 27, 2026
pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Jul 30, 2026
`test_cancel_backup` and `test_cancel_restore` assert that a cancellation is
prompt, but they measured it with a client-side `time.monotonic()` stopwatch
spanning `kill_query` through `wait_status`. In this harness every
`node.query(...)` is a `docker exec` of a fresh `clickhouse-client` (0.5-1 s
each), and that window held three to four of them plus `wait_status`'s
whole-second poll quantum, so the assertion bounded harness round-trip overhead
rather than the cancellation.

The result was a chronic flaky failure: 24 rows over 25 days across 13 pull
requests, two of them on master. Decomposing all 12 rows of that signature
family with timestamps the test already prints, the engine-side cancellation was
1.90-3.24 s (median 2.33) in every single failure against harness overhead of
2.94-5.91 s. The engine cancelled promptly every time; only the measurement was
wrong.

Measure the same interval between two server-recorded endpoints instead: the
KILL query's own `query_start_time_microseconds`, read from `system.query_log`
by an explicit `query_id`, and the initiator's `system.backups.end_time`. No
`clickhouse-client` launch is inside that interval, while the cluster-wide
cancellation still is -- `end_time` is stamped at the terminal transition, which
the initiator reaches only after `waitOtherHostsFinish`, so distributed
propagation remains bounded. Taking the start from the KILL statement itself
matters: in one recorded run a single client-to-server transition stalled
4.192 s, which alone would consume the whole budget.

The bound stays at 6 s. One assertion in, one assertion out, and no second
oracle: `query_duration_ms` was deliberately removed from this file in
19bcc55 and consolidated into the single end-to-end bound in
c26e0b4.

Separately, hoist `no_trash_checker.allow_errors` to checker entry so a body
failure surfaces as itself rather than being masked by `NoTrashChecker.__exit__`
asserting with both relaxation lists still empty -- which is what CIDB reported
for this test, hiding the real assertion. `allow_errors` is the correct one to
hoist because `__exit__` treats `expect_errors` as must-have-been-observed, so
hoisting that would create a new mask with inverted polarity for any failure
occurring before the cancellation. This matches ClickHouse#108459, which hoisted
`allow_errors` for two sibling functions in this file.

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

Fix flaky test_shutdown_cancels_backup and test_long_disconnection_stops_backup
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