Skip to content

Fix flaky test_insert_into_distributed::test_reconnect - #117133

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-flaky-distributed-reconnect
Aug 30, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-flaky-distributed-reconnect

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

test_insert_into_distributed::test_reconnect breaks the connection between a Distributed table and its remote shard, heals it, and then waits a fixed 5 seconds for the background sender to deliver the two pending inserts. That wait races the sender's retry interval: every failed attempt doubles it, starting at background_insert_sleep_time_ms (100 ms) and growing up to background_insert_max_sleep_time_ms, which defaults to 30 seconds. A newly inserted file does not shorten an interval the sender is already waiting out, because addFileAndSchedule calls scheduleAfter with overwrite = false, which is a no-op for an already delayed task. When the interval outgrows the 5 seconds, the test sees only the first row and fails with assert '1' == '3'.

Measured with two local servers, stopping and restarting the shard in place of the network partition: after a 60 second outage the sender's error_count reaches 9, which saturates the interval at the 30 second cap, and all rows arrive 20.2 seconds after the shard comes back — four times the 5 seconds the test allowed. With background_insert_max_sleep_time_ms = 1000 the same scenario delivers everything in 1.5 seconds.

The test now caps that setting on its table and waits for the observable state instead of sleeping: for the rows to appear on the shard, and — in place of the sleep that was there to let the send fail while the connection was down — for error_count in system.distribution_queue to grow. The latter also states the intent explicitly, that healing the partition has to exercise a reconnection. The setting is scoped to this test: instance_test_reconnect, its distributed table and local1 are used by no other test in the file.

The test has never failed on master. In the last 90 days it failed four times, all of them on pull requests and all in instrumented builds (two under amd_llvm_coverage, two under amd_msan) — which is what a slow machine accumulating more failed attempts inside the same partition window looks like. There is no tracking issue for it.

CI report of the failure this came from: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114747&sha=ad14224d5f960e11c6fddf144128ac30beed5cc8&name_0=PR&name_1=Integration%20tests%20%28amd_llvm_coverage%2C%206%2F8%29

Related: #114747

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Version info

  • Merged into: 26.9.1.397 (included in 26.9 and later)

The test broke the connection between a `Distributed` table and its remote shard,
healed it, and then waited a fixed 5 seconds for the background sender to deliver
the two pending inserts. That wait races the sender's retry interval: every failed
attempt doubles it, starting at `background_insert_sleep_time_ms` (100 ms) and
growing up to `background_insert_max_sleep_time_ms`, which defaults to 30 seconds.
A newly inserted file does not shorten an interval the sender is already waiting
out, because `addFileAndSchedule` calls `scheduleAfter` with `overwrite = false`,
which is a no-op for an already delayed task. So the test could see only the first
row and fail with `assert '1' == '3'`.

Measured with two local servers, stopping and restarting the shard in place of the
network partition: after a 60 second outage the sender's `error_count` reaches 9,
which saturates the interval at the 30 second cap, and all rows arrive 20.2 seconds
after the shard comes back - four times the 5 seconds the test allowed. With
`background_insert_max_sleep_time_ms = 1000` the same scenario delivers everything
in 1.5 seconds.

The test now caps that setting on its table and waits for the observable state
instead of sleeping: for the rows to appear on the shard, and - in place of the
sleep that was there to let the send fail while the connection was down - for
`error_count` in `system.distribution_queue` to grow. The latter also states the
intent explicitly, that healing the partition has to exercise a reconnection.

The test has never failed on `master`; in the last 90 days it failed four times,
all of them on pull requests and all in instrumented builds (two under
`amd_llvm_coverage`, two under `amd_msan`), which is what a slow machine
accumulating more failed attempts inside the same partition window looks like.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114747&sha=ad14224d5f960e11c6fddf144128ac30beed5cc8&name_0=PR&name_1=Integration%20tests%20%28amd_llvm_coverage%2C%206%2F8%29
Related: #114747

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [91963a6]

Summary: ✅


AI Review

Summary

This PR makes test_insert_into_distributed::test_reconnect wait on observable Distributed queue state instead of fixed sleeps, and caps the test table's retry backoff so the reconnection window stays bounded. I did not find a remaining correctness or isolation issue in the updated test logic, and the current PR CI report is all green.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 30, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Aug 30, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 30, 2026
Merged via the queue into master with commit 7c21a13 Aug 30, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-flaky-distributed-reconnect branch August 30, 2026 16:06
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants