Repository navigation
Conversation
…n heap corruption on master"
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
…hecks Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [27f347e] Summary: ❌
AI ReviewSummaryThis PR adds an experimental multi-stage distributed query execution path with stateless workers, streaming/persisted exchanges, distributed plan splitting, and tests. I found multiple unresolved correctness, cancellation, compatibility, and security issues in the new distributed control plane and plan serialization; these need fixes before this can be considered mergeable. Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Minimum required actions: fix the stream registration/authentication issue, make |
| return; | ||
| } | ||
|
|
||
| auto & slot = pending_connections[connection_key]; |
There was a problem hiding this comment.
This accepts and stores a producer socket for any query_id/stream pair before the server knows that such a stream belongs to a running query. Because the streaming exchange listener is unauthenticated, any host that can reach the configured listen address can send valid SourceHello packets with unique ids and make pending_connections retain a FutureConnection, eventfd, and socket indefinitely; no cleanupQuery or removePendingStreams will ever name those fake queries. That gives the new listener an unbounded FD/memory DoS path, and the same "first producer wins" behavior can also preempt a real stream if the ids are known. Please authenticate the handshake and/or pre-register expected streams so unknown producers are rejected instead of creating rendezvous slots.
|
|
||
| /// Task reached a terminal state on the worker. Release worker-side | ||
| /// bookkeeping for it (TaskState/progress/future). Best-effort. | ||
| tryForgetTask(task); |
There was a problem hiding this comment.
This cleanup RPC is best-effort, but it currently gates stage completion: setTaskFinished is not called until forgetTask returns, and forgetTask uses the normal long HTTP timeouts/retries. A worker task that has already reported Finished can therefore keep waitForStage blocked solely because the cleanup request is slow, and a Failed status is also delayed before it is surfaced. Please mark the terminal status first (or at least propagate failures first) and run forget on a bounded/best-effort path that cannot delay the stage result.
| /// task stuck in InMemoryExchange::getChunk never returns. The exchanges are not removed here: | ||
| /// the result reader still drains final_result after the driver finishes; removal happens when | ||
| /// the query pipeline is destroyed (see makeInMemoryExchangesCleaner). | ||
| InMemoryExchanges::instance()->cancelQuery(toString(unique_query_id)); |
There was a problem hiding this comment.
cleanup also runs after a local task throws, not only after onCancel. In that exception path the shared is_cancelled flag is still false, so this only wakes tasks blocked in InMemoryExchange; sibling tasks that are scanning, sleeping, or otherwise executing outside an exchange keep running while cleanup waits for every future. That can turn the first fragment exception into a long wait or hang instead of promptly failing the query. Set *is_cancelled = true before waking exchanges and waiting on the task futures, so the executor cancel callback stops all local fragments.
| LOG_DEBUG(logger, "Sending task {} to {}", task_info.task_id, task_info.endpoint_uri); | ||
| try | ||
| { | ||
| sendTask(task_info.endpoint_uri, task_info.task_id, task_description, unique_temp_file_path, context); |
There was a problem hiding this comment.
sendTask is synchronous and can spend up to the HTTP send/receive timeout here while ReadFromDistributedPlanSource::tryGenerate is holding executor_mutex. During that window onCancel can set the flag, but it cannot enter cleanup or send cancel/forget for a task that the worker may already have accepted, because the task is not tracked until this call returns. A KILL QUERY SYNC during remote startup can therefore wait for the start RPC timeout while the worker keeps running the fragment. The start path needs to be cancellable/bounded, or the task must be tracked early enough that cleanup can cancel it while the start request is in flight.
| --in_flight_request_count; | ||
| enqueueGetStatus(); | ||
| }); | ||
| ++in_flight_request_count; |
There was a problem hiding this comment.
The in-flight slot is reserved after scheduleOrThrow, but the scheduled callback can run immediately. For a fast status response it can execute --in_flight_request_count while the counter is still zero, recurse into enqueueGetStatus with a negative count, and bypass the max_in_flight_requests gate. That defeats the tracker’s concurrency bound and can drive extra scheduleOrThrow calls from inside the tracker thread. Reserve the slot before scheduling, and roll it back if scheduling throws.
| if (it == tasks.end()) | ||
| return Result::UnknownTaskId; | ||
|
|
||
| tasks.erase(it); |
There was a problem hiding this comment.
forget drops the only TaskState without checking whether the task is terminal. If a cleanup request arrives out of order, is retried against the wrong task id, or is sent by another authenticated interserver caller while the fragment is still running, later cancel/get_status see UnknownTaskId and shutdown no longer has this task in the map to cancel or wait for it. The task thread can then continue writing exchange streams or temporary files with no owner. Please make forgetTask fail or defer while completion_future is not ready, or cancel and wait before erasing the task state.
| if (deferred_row_level_filter || deferred_prewhere_info) | ||
| throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, | ||
| "make_distributed_plan does not support a distributed read with deferred FINAL filters"); | ||
| if (analyzed_result_ptr && analyzed_result_ptr->readFromProjection()) |
There was a problem hiding this comment.
This rejection only runs for bucketed reads, but a non-bucket ReadFromMergeTree can still be serialized after the second optimization pass has replaced it with a projection read. The serialized form records only the base table name and column list; deserialize reconstructs the step with MergeTreeDataSelectExecutor on the base table snapshot, not the projection snapshot/name. For aggregate or normal projections whose columns/actions do not match the base table, the remote fragment will either read the wrong source or fail while building the downstream projection steps. Please reject any analyzed_result_ptr->readFromProjection() before serialization unless the projection identity and snapshot are serialized and restored.
| prewhere_actions.serialize(ctx.out, ctx.registry); | ||
| writeStringBinary(prewhere_column_name, ctx.out); | ||
| writeBinary(remove_prewhere_column, ctx.out); | ||
| writeBinary(need_filter, ctx.out); |
There was a problem hiding this comment.
QueryPlan::serialize(max_supported_version) can still negotiate and write version 0 for an older remote server, but IQueryPlanStep::Serialization does not carry that negotiated version, so this new field is written unconditionally even when the stream header says the old format. An older server will deserialize PrewhereInfo without consuming need_filter, leaving the extra byte to be read as the next field and corrupting the rest of the serialized plan. Please propagate the plan serialization version into step serialization/deserialization and either omit/default need_filter for version 0, or refuse to serialize plans containing version-1-only fields to a version 0 peer.
Co-Authored-By: Claude Fable 5 <[email protected]>
Related: #107122
Related: #107146
Related: #107160
Changelog category (leave one):
Draft, never to be merged: the second half of the corruption repro experiment — the #107146 branch (multistage distributed queries + cancellation deadlock fixes) plus the same two crash-amplifying settings as #107160 (the plain-master repro PR).
How to read the results across the two PRs: crashes in both mean the bug is in shared infrastructure, not the distributed feature; crashes only here mean the feature is involved, and the enlarged ASan quarantine should yield a
heap-use-after-freereport that names the actual buggy code.🤖 Generated with Claude Code