Skip to content

Reduce flakiness of test_distributed_ddl_parallel and test_restore_replica - #108933

Merged
cv4g merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-distributed-ddl-parallel-and-restore-replica-flaky
Jul 2, 2026
Merged

cv4g merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-distributed-ddl-parallel-and-restore-replica-flaky

Conversation

@groeneai

@groeneai groeneai commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #108896

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

Reduce flakiness of two integration tests that fail together under sanitizer load (asan/msan), reported on PR #108896 (CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108896&sha=680c1a359cb1def9c09acf4dc2d33cc90466c3aa&name_0=PR&name_1=Integration%20tests%20%28amd_asan%2C%20old%20analyzer%2C%203%2F6%29). Both are CI-only flakes: 0 master failures in 30 days, hits spread across unrelated PRs (#107442, #107566, #107652, #108896). No tracking issue exists.

test_distributed_ddl_parallel::test_smoke_parallel_dict_reload fails with Code: 159. TIMEOUT_EXCEEDED: Pipe read timeout exceeded 10000 milliseconds ... ShellCommandSource. The slow_dict_3 / slow_dict_7 executable-dictionary sources rely on the default command_read_timeout of 10s (ShellCommandSource.h). The test issues 30 concurrent SYSTEM RELOAD DICTIONARY ON CLUSTER, each spawning a sleep command. Under sanitizer slowdown the server thread can fail to read the command pipe within 10s and aborts the load, even though the command itself only sleeps 3-7s. Fix: set command_read_timeout to 60s on both dictionaries. The commands never approach 60s, so nothing is masked; the 30-thread concurrency that exercises DDL queueing (above cluster_b.pool_size = 20) is preserved.

Verified deterministically: a sleep 3 executable dict with command_read_timeout=2000 reproduces the exact Code: 159 Pipe read timeout exceeded 2000 milliseconds ... ShellCommandSource; raising it to 60000 makes the same reload complete in ~3s and load the dictionary.

test_restore_replica (parallel / sequential / keeps_duplicate_parts) fails with Code: 210. NetException: Connection refused (NETWORK_ERROR) when a server node is transiently unreachable under sanitizer load (sibling subtests in the same run still pass, so the node recovers). The mutating queries (SYSTEM RESTART/RESTORE/SYNC REPLICA, INSERT) had no connection-level retry, while check_data already retries via assert_eq_with_retry. Fix: a query_with_connect_retry helper that retries only on "Connection refused". That error means the TCP connection was rejected and the query never reached the server, so retrying is safe even for the non-idempotent INSERT / SYSTEM RESTORE REPLICA statements (including the dedup-window-0 inserts). Any other error is re-raised immediately.

Verified deterministically: querying a closed port yields Code: 210 Connection refused (NETWORK_ERROR); the helper retries while the node is down and succeeds the moment it becomes reachable.

Test-only change (one dictionary config, one test file). No product code is modified.

Version info

  • Merged into: 26.7.1.427 (included in 26.7 and later)

…plica

Both integration tests fail together under sanitizer load (asan/msan) with
0 master failures in 30 days; hits spread across unrelated PRs.

test_smoke_parallel_dict_reload: the executable-dictionary sources slow_dict_3
and slow_dict_7 use the default 10s command_read_timeout. With 30 concurrent
SYSTEM RELOAD DICTIONARY ON CLUSTER under sanitizer slowdown, the server thread
can fail to read the command pipe within 10s and aborts with
TIMEOUT_EXCEEDED 'Pipe read timeout exceeded', even though the command only
sleeps 3-7s. Raise command_read_timeout to 60s on both dictionaries. The
commands never approach 60s, so nothing is masked and the concurrency that
exercises DDL queueing (above cluster_b.pool_size=20) is preserved.

test_restore_replica: mutating queries (SYSTEM RESTART/RESTORE/SYNC REPLICA,
INSERT) had no connection-level retry and fail with Connection refused when a
node is transiently unreachable under sanitizer load. Add query_with_connect_retry
that retries only on 'Connection refused'. Because that error means the TCP
connection was rejected and the query never reached the server, retrying is safe
even for the non-idempotent statements in these tests.

Test-only change. No product code modified.

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? Yes. dict_reload: an executable dict with sleep 3 + command_read_timeout=2000 reproduces Code: 159. Pipe read timeout exceeded 2000 milliseconds ... ShellCommandSource on demand. restore_replica: querying a closed TCP port reproduces Code: 210. NetException: Connection refused (NETWORK_ERROR) on demand.
b Root cause explained? dict_reload: 30 concurrent RELOAD DICTIONARY ON CLUSTER each spawn a sleep shell command; under sanitizer slowdown the server thread fails to read the command pipe within the default 10s command_read_timeout and aborts the load with TIMEOUT_EXCEEDED, even though the command only sleeps 3-7s. restore_replica: a node is transiently unreachable under sanitizer load; the bare mutating queries had no connection-level retry, so Connection refused fails the test (sibling subtests in the same run still pass, so the node recovers).
c Fix matches root cause? Yes. dict_reload: raise command_read_timeout to 60s on both slow dicts (directly the timeout that fires). restore_replica: retry only on Connection refused (directly the error that fires). Neither widens an assertion, reduces data, nor adds no-random-*.
d Test intent preserved / new tests added? Preserved. dict_reload keeps the 30-thread concurrency (still above cluster_b.pool_size=20, so DDL queueing and the check_log "Node exists" regression check are still exercised); commands never approach 60s so nothing is masked. restore_replica retries only a pre-execution TCP failure; all assertions and the restore logic are unchanged. No new behavior to test (test-harness hardening).
e Both directions demonstrated? Yes. dict_reload: command_read_timeout=2000+sleep 3 FAILS with the exact Code 159; raising to 60000 PASSES (reload completes ~3s, dict LOADED, dictGet returns value). restore_replica: helper retries while a port is closed and the query fails, then succeeds the instant a server binds that port.
f Fix is general across code paths? N/A (test-harness fix, not a product code bug). Both slow dicts (slow_dict_3, slow_dict_7) get the timeout; all bare mutating queries in restore_replica are routed through the retry helper.
g Fix generalizes across inputs? N/A (test-harness fix, not a code bug).
h Backward compatible? N/A (test-harness fix, no product/setting/format change).
i Invariants and contracts preserved? Yes. The Connection refused-only retry is safe even for non-idempotent statements (INSERT, SYSTEM RESTORE REPLICA, including the dedup-window-0 inserts) because a refused TCP connection means the query never reached the server, so it cannot have partially executed. Any other error is re-raised immediately.

Session id: cron:clickhouse-worker-slot-6:20260630-114300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix - could you review? Test-only flaky-test hardening: raises command_read_timeout on the executable dictionaries in test_distributed_ddl_parallel (the 10s default times out the sleep command under sanitizer load), and adds a Connection-refused-only retry around the mutating queries in test_restore_replica (transient node unreachability under sanitizer load). Both fail together with 0 master failures across unrelated PRs. Reproduced and verified deterministically in both directions (see the PR description and the gate comment).

def fill_nodes(nodes):
for node in nodes:
node.query("DROP TABLE IF EXISTS test SYNC")
query_with_connect_retry(node, "DROP TABLE IF EXISTS test SYNC")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@groeneai Did the CI failures report failures to connect or is this a precautionary measure?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Real failures, not precautionary. The three test_restore_replica failures in the report on #108896 (Integration tests (amd_asan, old analyzer, 3/6), head 680c1a3) all raised:

Code: 210. DB::NetException: Connection refused (172.16.2.7:9000). (NETWORK_ERROR)

The refused address is the node's own native port, and the failing queries were plain single-node statements (DROP TABLE IF EXISTS test SYNC during fixture setup/teardown), so clickhouse-client could not open its connection and the query never reached the server. CIDB 30d: the same signature on 4 PRs, 0 on master.

I have tightened the helper (d50d0ef) so it retries only this exact case: QueryRuntimeException with return code 210 and Connection refused (<this node ip>:9000). Any other error, including a server-side or remote/Keeper refusal with a different address, is re-raised. See the reply to the automated review on the helper below.

report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108896&sha=680c1a359cb1def9c09acf4dc2d33cc90466c3aa&name_0=Integration%20tests%20%28amd_asan%2C%20old%20analyzer%2C%203%2F6%29

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

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d50d0ef]

Summary: ✅


AI Review

Summary

This is a test-only hardening PR: it raises the executable dictionary read timeout used by test_distributed_ddl_parallel and adds a narrowly scoped retry for pre-query client connection refusals in test_restore_replica. The current retry condition is constrained to QueryRuntimeException code 210 with the target node's own ip_address:9000, so the earlier concern about retrying server-side or downstream Connection refused errors no longer holds. I found no remaining correctness or safety findings to post inline.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 30, 2026
Restrict query_with_connect_retry to a provable pre-query client
connection failure: a NETWORK_ERROR (code 210) whose message reports
"Connection refused (<node ip>:9000)" for the node's own address. In
that case clickhouse-client never opened the connection, so the query
never reached any server and retrying is safe even for non-idempotent
statements (INSERT, SYSTEM RESTORE REPLICA ... ON CLUSTER).

A server-side or downstream "Connection refused" (remote shard or
Keeper) carries a different address and is now re-raised immediately,
so an already-enqueued ON CLUSTER DDL or a partially-applied INSERT is
never resubmitted.

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

clickhouse-gh Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.55% 85.74% +0.20%
Functions 91.46% 91.47% +0.00%
Branches 77.45% 78.05% +0.60%

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

Newly covered by added/modified tests: 1116 line(s), 17 function(s) across 22 file(s) · Details

Top files
  • src/Interpreters/Context.cpp: 687 line(s), 1 function(s)
  • src/Interpreters/Aggregator.cpp: 249 line(s)
  • src/Core/BackgroundSchedulePool.cpp: 88 line(s), 6 function(s)
  • src/Backups/BackupEntriesCollector.cpp: 28 line(s), 2 function(s)
  • src/Core/ServerSettings.cpp: 23 line(s)

Full report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — d50d0ef

CI fully finished (Finish Workflow + Mergeable Check: success). This PR reduces flakiness of test_distributed_ddl_parallel (executable-dict command_read_timeout) and test_restore_replica (connect-refused-only retry). No failures: zero test-level FAIL/ERROR rows in CIDB for this commit; the only non-green GitHub check is the private Cloud sync.

Check / test Reason Owner
CH Inc sync - CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260630-173000

@cv4g
cv4g added this pull request to the merge queue Jul 2, 2026
Merged via the queue into ClickHouse:master with commit 5668551 Jul 2, 2026
174 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
pull Bot pushed a commit to erickirt/ClickHouse that referenced this pull request Aug 3, 2026
03568_udf_memory_tracking fails sporadically on Stateless tests (amd_msan,
WasmEdge, parallel, 2/2) with exit code 242 (UDF_EXECUTION_FAILED) wrapping
"Code: 159 Pipe read timeout exceeded 10000 milliseconds".

This is not a test timeout: the failing runs die in 13.7 s / 16.3 s / 27.3 s
against the 600 s per-test limit. It is a per-invocation bound.

test_function is declared with execute_direct=0 and no command_read_timeout,
so ExternalUserDefinedExecutableFunctionsLoader.cpp:234 gives it the 10000 ms
default. execute_direct=0 means every call vfork+execs /bin/sh -c "awk ...",
and test_function is not an executable_pool, so a fresh pipe and process are
created per call. The test uses max_block_size = 1 over numbers(40) and
numbers(60), i.e. 100 independent fork/exec round-trips; that per-block shape
is the coverage the test exists for.

The read clock is armed independently of the writer's progress:
ShellCommandSource spawns each SendDataTask on a separate thread and builds
the input format over timeout_command_out immediately, so the 10 s budget
covers vfork, exec, sh and awk startup plus the scheduling delay of our own
writer thread. Under MSan in a loaded parallel bucket one round-trip can
exceed it, and one slow read out of 100 fails the whole query. The two
distinct throw sites across the reports (once while reading the header, twice
inside ParallelParsingInputFormat) confirm a startup-window stall.

PR ClickHouse#107699 cut the round-trips from 300 to 100. That lowers the number of
dice rolls but leaves the per-roll ceiling untouched, which is why the
failure carried over from TSan to MSan; trimming the workload again would
attack the wrong term and erode coverage.

Every assertion is unchanged: both memory checks, count() = 2, the 100-block
workload and the reference file. Nothing is masked either: awk on one row is
sub-millisecond work, all 100 round-trips take 0.43 s locally, and the bound
stays finite at 60 s so a genuine hang still fails. The same knob at the same
value already fixed the identical signature for executable dictionaries in
ClickHouse#108933.

Closes: ClickHouse#112994
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ibuted-ddl-parallel-and-restore-replica-flaky

Reduce flakiness of test_distributed_ddl_parallel and test_restore_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-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.

4 participants