Repository navigation
Cherry pick #104167 to 26.3: Make test_cluster_all_replicas_query deterministic by gating on a pause-effective probe - #119446
Merged
Conversation
…heck The test previously asserted that pausing `node1` would cause `clusterAllReplicas(test_cluster, default.local_table)` to fail with `ALL_CONNECTION_TRIES_FAILED`. `cluster.pause_container` uses Docker's cgroup freezer, which takes effect quickly but not synchronously with in-flight TCP traffic, so the SELECT can race the freezer: `node1` can complete the TCP handshake and the tiny server greeting before being suspended, every per-replica shard succeeds, and the query returns a clean `count()` with `error == ''`. The assertion then fails spuriously. This is the chronic flake tracked under issues #103819 and #103820, which surfaced after the `857 ms` formatting fix in PR #103780. Fix: poll a fast probe `SELECT 1 FROM remote('node1:9000', system.one)` inside the pause context until it raises `QueryRuntimeException`. Once that probe fails, connections to `node1` are demonstrably blocked and the actual `clusterAllReplicas` test can run deterministically. The 30-second deadline accommodates slow CI runners; in practice the probe fails on the first or second iteration. The original assertions (`ALL_CONNECTION_TRIES_FAILED in error`, `857 ms in error`) are unchanged — the fix only removes the timing race.
Per @alexey-milovidov's review on PR #104167: instead of a per-test polling loop in `test_cluster_all_replicas_query`, fix `cluster.pause_container` itself so every caller gets a deterministic freeze. After `docker compose pause` returns, Docker's cgroup freezer suspends user-space tasks asynchronously with respect to in-flight TCP traffic. The kernel can still complete the TCP three-way handshake for fresh connections, and a short application greeting that is already buffered in the socket can flow back to the client before the freeze fully blocks the server's accept/read/write loop. Tests that assert on connection failure under `pause_container` see the very first probe succeed and flake (issues `#103819`, `#103820`). The new helper `_wait_for_pause_effective` polls a sibling ClickHouse node with a tight `remote(<paused>:9000, system.one)` probe until it raises `QueryRuntimeException` — the moment fresh ClickHouse handshakes to the paused container can no longer complete. Both `pause_container` and `pause_container_using_signal` now block on this probe by default; callers can opt out with `wait_for_paused=False`. For non-ClickHouse containers (Kafka, MongoDB, etc.) the helper is a no-op because we cannot speak the application protocol from a sibling. The current Kafka callers do not assert on freeze timing — they wait for log lines emitted well after the freeze takes effect — so the absence of a probe is benign. Reverts the per-test polling loop added earlier in this PR; the global helper subsumes it. Other ClickHouse-pause callers (`test_distributed_load_balancing`, `test_hedged_requests`, `test_distributed_frozen_replica::test_distributed_query`) automatically inherit the same guarantee. Co-Authored-By: Claude Opus 4.7 <[email protected]>
The previous version of `pause_container` and `pause_container_using_signal` called `_wait_for_pause_effective` outside the `try` that wraps `yield`. If the probe timed out and raised, the container was paused but `unpause()` was never reached, leaving the container permanently paused and cascading into unrelated test failures in the same suite. Move `_wait_for_pause_effective` inside the same `try` whose `finally` guarantees the matching unpause call. Cleanup now runs in every exit path: probe success, probe timeout, or caller exception. Same fix applied to both `pause_container` (docker compose pause + SIGSTOP fallback) and `pause_container_using_signal` (SIGSTOP-only). When the docker pause itself fails AND the SIGSTOP fallback also fails, no container is paused, so the existing "no inner try" behavior is correct and unchanged.
…d-frozen-replica-pause-race Make test_cluster_all_replicas_query deterministic by gating on a pause-effective probe
PedroTadim
added a commit
that referenced
this pull request
Sep 11, 2026
Cherry-pick of #105112 (fix chronic flaky test_distributed_frozen_replica: bypass connection pool in pause-effective probe) onto 26.3. The bot's base branch was cut before #119447 landed the prerequisite #104167, so `_wait_for_pause_effective` was absent entirely. Merged the current 26.3 tip first, which resolved that. The one remaining conflict was in the `pause_container` docstring. Kept the new paragraph describing the 90s `wait_timeout` default (part of this PR) and dropped the reinstated "(whether via `docker compose pause` or the `SIGSTOP` fallback)" clause: 26.3's `pause_container` has no SIGSTOP fallback, as resolved in #119446. `used_signal` predates #105112 in the merge base and is not touched by this PR, so it stays out of the backport. `_wait_for_pause_effective` and `pause_container_using_signal` are identical to master. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #104167
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job