Skip to content

Relax brittle 'receive timeout' assertion in test_distributed_frozen_replica - #103780

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-test-distributed-frozen-replica-receive-timeout-assertion
Apr 30, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-test-distributed-frozen-replica-receive-timeout-assertion

Conversation

@groeneai

@groeneai groeneai commented Apr 30, 2026 •

Copy link
Copy Markdown
Collaborator

The integration test test_distributed_frozen_replica/test.py::test_cluster_all_replicas_query fails intermittently because it asserts the literal substring "receive timeout 857 ms" (the configured handshake_timeout_ms) appears in the failure message — but only one of three socket-timeout code paths produces that exact phrasing.

Root cause

Three places in the codebase format socket-read-timeout errors:

Path Format string Contains "receive timeout"?
src/Common/AsyncTaskExecutor.cpp:124 (async I/O fiber) ({}, receive timeout {} ms) Yes
src/Client/HedgedConnections.cpp:449 (hedged-connection failover) ({}, receive timeout {} ms) Yes
src/IO/ReadBufferFromPocoSocket.cpp:88 (synchronous Poco read) (peer: {}, local: {}, {} ms) No
src/Server/ProxyV1Handler.cpp:124 (Proxy v1 wire handler) ({}, {} ms) No

All four formats include the timeout value formatted as {} ms. When the 857-ms handshake fires through the synchronous ReadBufferFromPocoSocket path (more likely on slow sanitizer builds — observed mostly on Integration tests (amd_msan, 1/6), (amd_tsan, 1/6), and (amd_asan_ubsan, db disk, old analyzer, 1/6)), the assertion fails because the error contains 857 ms but not receive timeout 857 ms.

Example failing CIDB log (pull_request_number=100399, Integration tests (amd_msan, 1/6)):

DB::Exception: All connection tries failed. Log:

Timeout exceeded while reading from socket (socket ([2001:3984:3989::11]:9000), receive timeout 5000 ms)
Code: 209. DB::NetException: Timeout exceeded while reading from socket
  (peer: [2001:3984:3989::11]:9000, local: [2001:3984:3989::13]:35828, 857 ms): ...

The only receive timeout phrase here is for the unrelated default-5000ms socket-receive timer. The 857-ms handshake-timeout cancellation surfaces through the sync path and prints 857 ms without the prefix.

Fix

Relax the assertion from "receive timeout 857 ms" to "857 ms". The test still verifies the configured handshake_timeout_ms=857 actually took effect (the value appears in the error), but no longer locks the assertion to one specific socket-error code path. The companion assertion "ALL_CONNECTION_TRIES_FAILED" in error already verifies the high-level failure mode.

Failure history

Over the last 30 days, ~10 failures across 9 distinct unrelated PRs in the assertion-mismatch mode (this PR's target). Concentrated on slow sanitizer + old-analyzer integration runners.

CI report data: https://play.clickhouse.com/

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.201 (included in 26.5 and later)
  • Backported to: 26.3.33.59

…replica

The test asserted that the error from a failed clusterAllReplicas query
contains the literal substring "receive timeout 857 ms" — the configured
`handshake_timeout_ms`.

That phrasing is only emitted by the async `HedgedConnections` /
`AsyncTaskExecutor` socket-timeout code path
(`src/Client/HedgedConnections.cpp:449`,
`src/Common/AsyncTaskExecutor.cpp:124`). The synchronous
`ReadBufferFromPocoSocket::nextImpl` path
(`src/IO/ReadBufferFromPocoSocket.cpp:88`) and the ProxyV1 handler path
(`src/Server/ProxyV1Handler.cpp:124`) both format the same error
without the "receive timeout" prefix:

  "Timeout exceeded while reading from socket (peer: ..., local: ..., {} ms)"
  "Timeout exceeded while reading from socket ({}, {} ms)"

When the 857ms handshake fires through the synchronous path (more
likely on slow sanitizer builds — observed mostly on `amd_msan`,
`amd_tsan`, `amd_asan_ubsan, db disk, old analyzer`), the error
contains "857 ms" but not "receive timeout 857 ms", so the assertion
fails.

All three timeout-error formats include the timeout value as
"{} ms", so check for "857 ms" alone. The test still verifies that the
configured handshake timeout took effect — it just no longer locks the
assertion to one specific socket-error code path.

Failure history: ~10 hits across 9 distinct PRs over the last 30 days.

CI report data: https://play.clickhouse.com/
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (per TASK.md Phase 4 Step 9):

a) Deterministic repro? — Yes, in the CI evidence form: CIDB has 10 failures across 9 unrelated PRs over the last 30 days where test.py:109 raises AssertionError: assert 'receive timeout 857 ms' in '<full error string>', with the <full error string> containing 857 ms (sync-path format) but not the receive timeout prefix. Sample failure context for pull_request_number=100399, Integration tests (amd_msan, 1/6):

DB::Exception: All connection tries failed. Log:

Timeout exceeded while reading from socket
  (peer: [2001:3984:3989::11]:9000, local: [...]:35828, 857 ms): (node1:9000, ...)

The 857-ms handshake-timeout cancellation surfaces through ReadBufferFromPocoSocket.cpp:88 and prints 857 ms without receive timeout. The assertion mismatch is reproducible from those CI runs verbatim.

b) Root cause explained? — Yes. The codebase emits the same logical event ("socket read hit configured timeout") through four format-string sites:

  • AsyncTaskExecutor.cpp:124 and HedgedConnections.cpp:449 print (..., receive timeout {} ms)
  • ReadBufferFromPocoSocket.cpp:88 prints (peer: ..., local: ..., {} ms) — no receive timeout
  • ProxyV1Handler.cpp:124 prints ({}, {} ms) — no receive timeout

When clusterAllReplicas retries replicas with handshake_timeout_ms=857 and the synchronous Poco read path is the one that observes the timeout, the error string lacks the receive timeout prefix. All four formats include the value as {} ms, so the universal substring is 857 ms.

c) Fix matches root cause? — Yes. Replace "receive timeout 857 ms" with "857 ms". This drops the format-specific prefix that fails for two of the four code paths while preserving the timeout-value check.

d) Test intent preserved? — Yes. The test still asserts:

  • "ALL_CONNECTION_TRIES_FAILED" in error (line 108) — connection-failover mode
  • "857 ms" in error (line 109, post-fix) — the configured handshake timeout was actually applied (still catches a regression where the 857ms gets ignored or replaced with a different value, e.g., a 5000ms default)

The narrower regression class the previous assertion accidentally caught — "the message format is exactly the async-path one" — was never the test's intent; it was a side effect of which path happened to fire on the original developer's machine.

e) Both directions demonstrated? — Asymmetric demonstration:

  • WITHOUT fix: 10 CIDB-recorded failures in 30 days where error contains 857 ms but the "receive timeout 857 ms" assertion fails. Logs above.
  • WITH fix: "857 ms" is a substring of all four error formats, so the assertion passes whenever the previous one passed and whenever the previous one failed-but-error-still-contained-the-value. The fix loosens the constraint, so it can never make a previously-passing run fail.

The fix is a one-line test-only change with no production C++ touched, no behavior gated, and no risk of false positives in the relaxed assertion (the value 857 is uniquely the configured handshake_timeout_ms; no other timeout in this query uses 857ms).

Tracker task: 2026-04-30-ci-testdistributedfrozenreplica-chro (failure modes A/C/F still need separate work — empty-error race, count-mismatch race, pause_container Docker flake).

Session: cron:clickhouse-ci-task-worker:20260430-094500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @azat — could you review this? It's a one-line test-only change in test_distributed_frozen_replica that relaxes a brittle assertion (receive timeout 857 ms → 857 ms) so the test no longer locks itself to one of the four ClickHouse socket-timeout error-message formats. Root cause and CIDB evidence in the PR body and pre-PR validation gate comment above.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Apr 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c0214e8]

Summary: ✅


AI Review

Summary

The PR updates a brittle integration-test assertion in test_cluster_all_replicas_query from a path-specific message fragment to the timeout value (857 ms), which preserves the intended behavioral check while removing dependence on one specific socket-error formatting path. The change is scoped, consistent with the stated flaky-failure mode, and safe to merge.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 30, 2026
@alexey-milovidov alexey-milovidov self-assigned this Apr 30, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 30, 2026
Merged via the queue into ClickHouse:master with commit 7214e6d Apr 30, 2026
165 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 30, 2026
pull Bot pushed a commit to Haofei/ClickHouse that referenced this pull request May 6, 2026
…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 ClickHouse#103819 and ClickHouse#103820,
which surfaced after the `857 ms` formatting fix in PR ClickHouse#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.
devcrafter pushed a commit that referenced this pull request May 7, 2026
…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.
@PedroTadim

Copy link
Copy Markdown
Member

Backporting to fix CI in 26.3 and 26.4

@robot-ch-test-poll3 robot-ch-test-poll3 added pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Sep 11, 2026
alexey-milovidov added a commit that referenced this pull request Sep 12, 2026
Backport #103780 to 26.3: Relax brittle 'receive timeout' assertion in test_distributed_frozen_replica
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
…ssertion in test_distributed_frozen_replica
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-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants