Skip to content

Fix flaky 04604_parallel_replicas_unsent_query_not_cancelled on instrumented builds - #121874

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04604-coverage-stack-trace
Sep 24, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04604-coverage-stack-trace

Conversation

@groeneai

@groeneai groeneai commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

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

04604_parallel_replicas_unsent_query_not_cancelled now asks the server not to build a text stack trace for the replica query it deliberately cancels.

Description

04604_parallel_replicas_unsent_query_not_cancelled fails only on the coverage lanes: 29 times
on master in 30 days, all on amd_llvm_coverage (1.87 % on 3/3), versus 0 of ~15 000 runs
elsewhere
; 28 are hidden as OK by the flaky relabelling. Failing job:
https://github.com/ClickHouse/ClickHouse/actions/runs/35917766208/job/107380811116

Not a cancellation bug. From that job's own artifacts: the follower receives and honours the
Cancel 11 ms after starting
and throws QUERY_WAS_CANCELLED_BY_CLIENT. It then spends
4.17 more seconds symbolizing that exception's text stack trace (trace_log caught the
thread 8/8 times there on one DWARF-lookup stack), and its system.processes row is released
only when that finishes. The test polls for ~3.4 s, so it reports a parked replica that was
cancelled 4.1 s earlier. That trace is computed only because system.query_log is configured,
and is intermittent because the trace cache is per process (p50 1 ms, p99 2.2 s over that job's
4510 ExceptionBeforeStart rows).

So the test now sets calculate_text_stack_trace = 0, the setting already documented for exactly
this cost; #121512 made the same trade in two other tests last week. The poll budget,
receive_timeout, the assertion and the reference are untouched, so nothing is relaxed; the
margin becomes ~300x. I did not raise the timeout or add a retry: either would hide a real
cancellation gap.

Validation: on one binary the follower's stack_trace goes from 7199 bytes to empty, which also
proves the setting reaches the replica; with a failpoint that genuinely parks a follower it still
fails with the original signature (16/20 vs 14/20 unchanged); 100/100 green locally.

A query stays in system.processes while its exception trace is resolved. That is milliseconds on
a normal build, so I have not touched the shared path. stack_trace is now empty for this test's
queries, and a regression's log line loses its trace too; no assertion reads either.


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

Version info

  • Merged into: 26.10.1.604-master (included in 26.10 and later)

04604_parallel_replicas_unsent_query_not_cancelled fails only on the
amd_llvm_coverage lanes: 29 times on master over 30 days, every one of them on a
coverage lane (22/1174 = 1.87% on the plain 3/3 lane, 4/1179 on AsyncInsert+s3,
3/390 on s3+DBReplicated), against 0 of ~15000 runs on every non-coverage lane.
28 of the 29 are currently hidden as OK because the diagnostics rerun relabels
them flaky. The discriminator is the instrumented binary, not the Replicated
database and not s3: 22 of the 29 ran with no Replicated database at all.

It is not a cancellation bug. Measured from the failing job's own artifacts, the
follower receives and honours the Cancel 11 ms after its query starts, at its
first cancellation checkpoint, and throws QUERY_WAS_CANCELLED_BY_CLIENT. It then
spends 4.17 more seconds resolving that exception's text stack trace in
logExceptionBeforeStart, and its system.processes row is released only when that
finishes; trace_log caught the thread 8 of 8 times in the gap on a byte-identical
17-frame DWARF lookup stack, with both the real and the CPU timer firing at full
rate. Since code 735 sets log_error = false, the only thing that can demand the
trace is query_log_will_read, and log_queries is forced to 1 by the CI config, so
the whole 4.17 s exists to populate system.query_log.stack_trace for a query that
was cancelled on purpose. The cost is intermittent because StackTrace::toString
is cached per process on the frame triple: over all 4510 ExceptionBeforeStart
rows of that job the post-throw cost is p50 1 ms, p90 72 ms, p99 2202 ms, max
4533 ms. The test polls system.processes for ~3.4 s, so it reports a parked
replica that was in fact cancelled 4.1 s earlier.

Turn the symbolization off for the measured query. calculate_text_stack_trace is
the documented lever for exactly this cost and is already used this way by five
tests in the suite, so no new setting appears. The poll budget, receive_timeout,
the assertion and the reference are all untouched, which keeps the test's
discriminating power intact and leaves a ~300x margin over the 11 ms the
cancellation actually needs. Raising the timeout was rejected because it widens a
margin instead of removing the cause and would make a genuine regression cost
~60 s; a retry was rejected because it can mask a real cancellation gap; and
no-replicated-database was rejected because it would claim a mechanism the
measurements refute.

The setting reaches the follower through the per-replica context copy
(updateContextForParallelReplicas -> Context::createCopy) and is not in
initiator_only_setting_names, so nothing strips it. Verified on one binary: the
follower's query_log row carries a 7199-byte stack_trace without this change and
an empty one with it, while recording calculate_text_stack_trace = 0 on its own
row. Sensitivity was checked against a genuinely parked follower using the
parallel_replicas_delay_announcement failpoint, where the changed test still
reports "FAIL: 1 replica(s) still running" 16 times out of 20 versus 14 out of 20
for the unchanged test. 100 of 100 local runs green, 50 randomized and 50 not.

One consequence worth knowing: system.query_log.stack_trace is now empty for this
test's queries. No assertion depends on it, and a regression is still identified
by the reference diff and the server log.

Related: ClickHouse#113551
CI report: https://github.com/ClickHouse/ClickHouse/actions/runs/35917766208/job/107380811116

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 24, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 gate findings) plus my own cold
read of the resulting diff before any of the implementation notes (3 nits, no blockers, no majors).

# Sev Finding Verdict Evidence / action
1 ⚠️ The planned sensitivity control (revert the src/ line this test guards, then re-run it) was inconclusive: on a local debug build the changed test stayed green 6/6, but so did master's unmodified test on that same reverted binary, so the regression does not reproduce in that environment and the diff is not what made it green AGREE, control replaced Sensitivity measured instead against a follower that is genuinely parked (parallel_replicas_delay_announcement): the changed test still fails with the original FAIL: 1 replica(s) signature, and detects the parked follower 16/20 versus 14/20 for the unchanged test
2 💡 calculate_text_stack_trace also gates logQueryException (src/Interpreters/executeQuery.cpp:977), whose guard is log_error. A genuine regression of this test times out, so its server-log line will now carry its message but no symbolized trace AGREE, disclosed Stated in the PR description; the oracle is the .reference diff, which is untouched, and no assertion reads a trace
3 💡 The plan's source citation for how the setting reaches the follower named the Distributed/remote() helper rather than the parallel-replicas one AGREE, corrected before freeze The path that runs is updateContextForParallelReplicas -> Context::createCopy (full settings copy) and the setting is absent from initiator_only_setting_names; verified from source independently, and the follower's own query_log row records the setting as 0
4 💡 The new header paragraph is appended after the receive_timeout paragraph while the setting line sits before receive_timeout in the SETTINGS clause, so comment order and settings order disagree Noted, not blocking Cosmetic; both positions are the ones the fix plan prescribed
5 💡 Carrier check: one more stateless test reads system.processes keyed on a query id (05061_query_log_interface_enum_unknown) and was not in the enumerated set DISAGREE Verified not a carrier of this invariant: it observes its own running row, not the absence of secondary queries, so no timing bound applies to it. The three siblings that do bound an absence carry 25 s, 30 s and wall-clock budgets

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Also checked and clean: the diff is pure ASCII with no trailing whitespace,
the poll budget and receive_timeout are byte-unchanged, calculate_text_stack_trace is not in
the test runner's randomized set, and no profile or constraint in tests/config touches it.

Session id: cron:clickhouse-review-slot-10:20260924-010800

@clickhouse-gh clickhouse-gh Bot closed this Sep 24, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [88889a5]

Summary: ✅


AI Review

Summary

This PR narrows 04604_parallel_replicas_unsent_query_not_cancelled so coverage-only exception symbolization does not keep an already-cancelled replica visible in system.processes. I reviewed the current diff and the affected logExceptionBeforeStart / updateContextForParallelReplicas paths, and I did not find blockers, majors, or PR-metadata issues in the patch as submitted.

Final Verdict

✅ Approve. No new inline findings to post.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 24, 2026
@groeneai
groeneai requested a review from nickitat September 24, 2026 01:40
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 24, 2026
@PedroTadim PedroTadim self-assigned this Sep 24, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Sep 24, 2026
Merged via the queue into ClickHouse:master with commit b014c16 Sep 24, 2026
176 of 349 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 Sep 24, 2026
@clickhouse-gh clickhouse-gh Bot added comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). and removed comp-testing Test content only (no production code). labels Nov 22, 2026
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 comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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.

3 participants