Skip to content

Cherry pick #104167 to 26.3: Make test_cluster_all_replicas_query deterministic by gating on a pause-effective probe - #119446

Merged
PedroTadim merged 4 commits into
backport/26.3/104167from
cherrypick/26.3/104167
Sep 11, 2026
Merged

PedroTadim merged 4 commits into
backport/26.3/104167from
cherrypick/26.3/104167

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits May 6, 2026 00:56
…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
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Sep 11, 2026
@PedroTadim
PedroTadim merged commit 9d39093 into backport/26.3/104167 Sep 11, 2026
177 of 180 checks passed
@PedroTadim
PedroTadim deleted the cherrypick/26.3/104167 branch September 11, 2026 12:34
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants