Skip to content

Fix flaky 04239_streaming_combinations: wait for both UNION ALL sides - #106574

Merged
nikitamikhaylov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix/04239-streaming-union-race
Jun 6, 2026
Merged

nikitamikhaylov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix/04239-streaming-union-race

Conversation

@groeneai

@groeneai groeneai commented Jun 5, 2026 •

Copy link
Copy Markdown
Collaborator

The Test Regular Union Stream subtest of 04239_streaming_combinations spawns:

SELECT a FROM t_streaming_test UNION ALL SELECT a FROM t_streaming_test STREAM

against a table that already contains one row ('started', 0). Both UNION ALL sources scan that row and emit one started line each, so the expected reference begins with two started lines before any post-INSERT data.

The test synchronized with read_until "$fifo_1" "started", which returns after the FIRST started line. UNION ALL provides no ordering between sources, so the regular side's started could still be in flight when the test issues INSERTs. When that happens the streaming side emits a post-INSERT row (0) into the FIFO before the regular side's started reaches stdout, producing started\n0\nstarted\n0\n1 instead of the reference started\nstarted\n0\n0\n1. The race widens under distributed plan + s3 storage because of higher and more variable scheduling latency, which matches where CI saw the failures.

This patch extends read_until in streaming.lib with an optional target-count argument (defaults to 1, preserving existing callers) and updates the Test Regular Union Stream subtest to wait for both started markers before issuing the INSERTs. Post-INSERT rows are then appended at a deterministic position relative to both source rows.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106423&sha=c63e3b252e8a6bd504220f99031f9ba16a95ce09&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29

Verified locally: 20/20 passes with random settings disabled, 1/1 with default randomization. The race is timing-sensitive in CI; the fix removes the synchronization gap that allowed it.

Related: #106423
Caused by: #96130

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 to CHANGELOG.md):

...

Documentation entry for user-facing changes

  • Documentation entry is not required.

Version info

  • Merged into: 26.6.1.459

The "Test Regular Union Stream" subtest spawns

    SELECT a FROM t_streaming_test UNION ALL SELECT a FROM t_streaming_test STREAM

against a table that already contains one row (`'started'`, `0`). Both
`UNION ALL` sources scan that row and emit one `started` line each, so the
expected output starts with two `started` lines before any post-INSERT
data arrives.

The test previously synchronized with `read_until "$fifo_1" "started"`,
which returns after the FIRST `started` is observed. There is no
ordering guarantee between the two `UNION ALL` sources, so the regular
side's `started` could still be in flight when the test issues its
`INSERT`s. When that happens the streaming side emits a post-INSERT row
(`0`) into the FIFO before the regular side's `started` reaches stdout,
producing `started\n0\nstarted\n0\n1` instead of the reference
`started\nstarted\n0\n0\n1`. The race widens under `distributed plan` +
`s3 storage` because of the higher and more variable scheduling latency
of those configurations, which is exactly where CI saw the failures
(report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106423&sha=c63e3b252e8a6bd504220f99031f9ba16a95ce09&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29
PR: ClickHouse#106423).

This patch extends `read_until` in `streaming.lib` with an optional
target-count argument (defaults to 1, preserving existing callers) and
updates the `Test Regular Union Stream` subtest to wait for both
`started` markers before issuing the INSERTs, so the post-INSERT rows
are appended in a deterministic position relative to both source rows.

Verified locally: 20/20 passes with random settings disabled, 1/1 with
default randomization.

Caused by: ClickHouse#96130
Related: ClickHouse#106423
@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Partial. The CIDB diff started\n0\nstarted on PR #106423 is the precise fingerprint of the race — the streaming side emits a post-INSERT 0 before the regular side's started reaches stdout. The race is timing-sensitive (1 hit on PR #106423, 1 hit on PR #96130 in 30 days, 0 master hits), so a hard local repro of the bad ordering on a fast machine without s3 storage/distributed plan scheduling latency is not realistic.
b Root cause explained? SELECT a FROM t UNION ALL SELECT a FROM t STREAM has two sub-pipelines, each scanning the pre-existing ('started',0) row. UNION ALL provides no ordering between sources. The test's read_until "started" returns after the FIRST started, then issues INSERTs. If the second source's started is still in flight, the streaming side emits a post-INSERT 0 to the FIFO before the regular side's started reaches stdout — producing started\n0\nstarted\n0\n1 instead of started\nstarted\n0\n0\n1. distributed plan + s3 storage widens the timing window, which is exactly where CI saw the diff.
c Fix matches root cause? Yes. Extending read_until with an optional target-count and using read_until "$fifo_1" "started" 2 blocks until BOTH sources have flushed their started line. Post-INSERT rows then arrive at a deterministic position relative to both source rows, removing the ordering window.
d Test intent preserved / new tests added? Preserved. The test still exercises UNION ALL of regular + STREAM with both sides producing pre-existing rows. The synchronization point is moved one row later; the assertions on 0, 0, 1 post-INSERT remain. Other callers of read_until are unaffected (target-count defaults to 1). N/A on new tests — this is a flaky-test fix, not a code-bug regression.
e Both directions demonstrated? Partial. With the fix, 20/20 passes with --no-random-settings --no-random-merge-tree-settings and 1/1 with default randomization. The original failure mode is rare and timing-sensitive; on the local machine without s3 storage + distributed plan scheduling, a deterministic repro of the bad ordering on master is not feasible. The CIDB-reported diff exactly matches the race the fix removes.
f Fix is general, not a narrow patch? The change is targeted at the test that's failing — Test Regular Union Stream is the only read_until site in this test that depends on multiple sources flushing before an INSERT. The Test Stream Union Stream subtest waits for started from a single matching row (b%2=0) so it has no equivalent hazard. The read_until helper now supports the optional count argument, generalizable to any future test in the family with the same shape.

Session id: cron:clickhouse-ci-task-worker:20260605-151300

@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Michicosun — could you review this? It removes a synchronization race in the Test Regular Union Stream subtest of 04239_streaming_combinations by waiting for both UNION ALL sides to flush their pre-existing started row before issuing INSERTs (test-only change; streaming.lib read_until gains an optional target-count argument that defaults to 1).

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jun 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [abe6d09]

Summary: ✅


AI Review

Summary

The PR fixes a flaky 04239_streaming_combinations synchronization point by extending read_until with an optional target count and waiting for both UNION ALL inputs to emit started before issuing follow-up INSERTs. The change matches the reported race, preserves existing one-match callers through the default count, and I did not find a correctness issue that needs an inline comment.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.50% +0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.00% 77.10% +0.10%

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

Newly covered by added/modified tests: 413 line(s), 24 function(s) across 124 file(s) · Details

Top files
  • src/Storages/RabbitMQ/RabbitMQSource.cpp: 50 line(s), 2 function(s)
  • src/Coordination/KeeperStateMachine.cpp: 17 line(s)
  • src/Storages/RabbitMQ/StorageRabbitMQ.cpp: 16 line(s), 2 function(s)
  • src/AggregateFunctions/AggregateFunctionQuantileGK.cpp: 14 line(s)
  • src/Interpreters/DeadLetterQueue.cpp: 13 line(s), 1 function(s)

Full report

@nikitamikhaylov nikitamikhaylov self-assigned this Jun 6, 2026
@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Jun 6, 2026
Merged via the queue into ClickHouse:master with commit c8f1d75 Jun 6, 2026
166 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 6, 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 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