Repository navigation
Fix Pipeline stuck deadlock in PingPongProcessor with full_sorting_merge join - #98454
Merged
Merged
Conversation
…ng_merge` join The `ReadHeadBalancedProcessor` (`Order::First`) blocked in `prepare` waiting for a ping from `Order::Second` before processing any regular data. When the downstream `MergeJoinTransform` needed data from both sides, the right side (`Second`) couldn't consume enough rows to send the ping because the join was waiting for left-side data — a circular dependency that deadlocked the pipeline. The fix: don't block `Order::First` before `processRegularPorts`. Instead, try to receive the ping non-blockingly and let regular ports process data. The finish-time ping exchange (required for cleanup) is preserved. This is safe because `FilterBySetOnTheFlyTransform` already bypasses rows when the set is still in `Creating` state. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98355&sha=5183838a81ab41b4f3434e73aaca3fe02f3d3c59&name_0=PR&name_1=AST%20fuzzer%20%28amd_ubsan%29 Closes #57728 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
When `start_server` retries after the first `clickhouse start` attempt fails to respond, `clickhouse start` sees the existing PID file and reports "already running" — making all retries no-ops. This happens when the server started but failed to bind some ports (e.g. 9181, 9009) still held by a previous instance that hadn't fully terminated yet, especially under sanitizer builds which are slower. The fix: on retry attempts, force-stop any non-responsive server before starting a fresh one. On the first attempt nothing changes. On retries we've already waited 20 seconds — if `SELECT 1` still fails, the server won't recover and needs a restart with ports now freed. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98454&sha=48200cc58dec962ea1624acc23da4372e73fa52c&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
…art_server`" This reverts commit 71dc10f.
After `safeExit` (forceful shutdown due to stuck client connections), the kernel may still be cleaning up sockets, especially under sanitizer builds where `SYS_exit_group` is used. The `safeExit` path skips the normal `SCOPE_EXIT_SAFE` handler that closes interserver (9009) and Keeper (9181) listening sockets, leaving them to kernel cleanup which can race with the next server start. Add `wait_server_port_free` to check port availability before starting, so `start_server` waits for ports 9000, 9009, and 9181 to be released. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98454&sha=48200cc58dec962ea1624acc23da4372e73fa52c&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
…nce" This reverts commit 4ecce57.
Member
|
The test query does not reproduce the bug. Let's use this https://fiddle.clickhouse.com/f1022c9f-a474-4ca1-a55e-9f69fd851cb1 which reproduces. DROP TABLE IF EXISTS t;
DROP TABLE IF EXISTS t2;
CREATE TABLE t (`c` UInt64) ENGINE = MergeTree ORDER BY c;
INSERT INTO t SELECT * FROM numbers(1000000);
CREATE TABLE t2 (`c` UInt64) ENGINE = MergeTree ORDER BY c;
INSERT INTO t2 SELECT * FROM numbers(1000000);
SELECT count()
FROM (SELECT * FROM t) AS t1,
(SELECT * FROM t2 ORDER BY c ASC LIMIT 500000) AS t2s
WHERE t1.c = t2s.c
SETTINGS
max_rows_in_set_to_optimize_join = 100000000,
join_algorithm = 'full_sorting_merge',
query_plan_join_swap_table = 0,
max_threads = 2; |
The previous test with 1000 rows and `max_block_size = 10` did not trigger the circular dependency between `PingPongProcessor` and `MergeJoinTransform`. Use the reproducer from #98454 (comment) which reliably triggers the deadlock with larger data and appropriate settings. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Member
Author
|
Thanks, now the test is good. |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a "Pipeline stuck"
LOGICAL_ERRORexception caused by a circular dependency deadlock inPingPongProcessor(ReadHeadBalancedProcessor) when used with theFilterBySetOnTheFlyoptimization infull_sorting_mergejoins.The deadlock
The
ReadHeadBalancedProcessoruses a ping-pong protocol between two instances (Order::Firstfor the left side,Order::Secondfor the right side) to synchronize how much data each side reads before the filtering sets are exchanged. The protocol:Secondprocesses data, counting rows viaconsumeSecondsends a ping toFirstFirstreceives the ping and starts processingFirstsends a ping back after consuming enough rowsThe bug:
Order::Firstblocked inprepare(line 153) waiting for the ping before ever callingprocessRegularPorts. This meant the left-side sources never started. When the downstreamMergeJoinTransform(a Y-shaped processor that needs data from both sides) couldn't get left-side data, it stopped consuming from the right side. This caused backpressure that preventedOrder::Secondfrom pushing data throughFilterBySetOnTheFlyTransform, soconsumewas never called,ready_to_sendstayed false, and the ping was never sent.This was triggered by the AST fuzzer with
join_algorithm = 'full_sorting_merge',max_rows_in_set_to_optimize_join = 100000, andmax_block_size = 10— the small block size meant only ~20-30 rows could buffer betweenSecondandMergeJoinTransform, far fewer than the 100000 needed to trigger the ping.The fix
Remove the blocking
return Status::NeedDatabeforeprocessRegularPortsin the pre-processing ping check. Instead, attemptreceivePingnon-blockingly and fall through to process regular ports. The finish-time ping exchange (required for proper cleanup synchronization) is preserved.This is safe because:
FilterBySetOnTheFlyTransformalready bypasses rows when the set is still inCreatingstateOrder::Firststill won't try to send its ping until it receivesSecond's (gated byis_received)02383_join_and_filtering_settest passCI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98355&sha=5183838a81ab41b4f3434e73aaca3fe02f3d3c59&name_0=PR&name_1=AST%20fuzzer%20%28amd_ubsan%29
#98355
Closes #57728
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix "Pipeline stuck" exception in
full_sorting_mergejoins caused by a deadlock inPingPongProcessorwhen theFilterBySetOnTheFlyoptimization created a circular dependency withMergeJoinTransform.🤖 Generated with Claude Code
Version info
26.3.1.341