Repository navigation
Fix server abort when an Arrow Flight query throws while finishing - #129193
alexey-milovidov merged 3 commits into
Conversation
DoPut, DoGet, GetSchema and executeSQLtoTables_impl (GetFlightInfo, DoAction) called BlockIO::onFinish from a SCOPE_EXIT, so on a successful call it ran in a destructor. onFinish allocates through memory-tracked containers (getProcessorsProfileLogInfo, printPipeline) and runs finish callbacks; on a normal scope exit the memory tracker is allowed to throw, so a MEMORY_LIMIT_EXCEEDED there left the destructor and called std::terminate. The stress test hit it through memory_tracker_fault_probability once it started sending queries over Arrow Flight (ClickHouse#125517): Stress test (arm_release), master a8e6d0b, STID 2618-2444. Call onFinish on the normal path after the work try/catch, as BlockIO::executeWithCallbacks and executeTrivialBlockIO do, and keep only onCancelOrConnectionLoss in the guard. The executors over the pipeline are locals of the try block, so they are still destroyed before onFinish releases the memory reservation their spill state points to. If onFinish throws, the guard cancels and resets the pipeline and releases the workload resources during unwinding, and the exception reaches tryRunAndLogIfError, which returns an error status to the client. The test loops all four calls in a Flight session with fault injection; the unfixed server aborts within a few dozen iterations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261104-070900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261104-063000 |
|
cc @yakov-olkhovskiy @vitlibar, could you review this and add the |
|
Workflow [PR], commit [6e80da0] Summary: ✅
AI ReviewSummaryMoves Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested and no new inline findings to post. The existing bot-authored thread correctly remains resolved. |
…ry throws The previous commit called onFinish after the try block, so an exception from it reached only onCancelOrConnectionLoss in the scope guard. That path does not run the exception callbacks: with implicit_transaction = 1 in a named Flight session, the transaction begun by the query stayed in the session, and the next INSERT in that session ran inside it, skipped the implicit commit, reported success, and its rows were rolled back when the session closed. Call onFinish at the end of the try block instead, so a throw from it is handled by the existing catch and goes through onException (rollback of the implicit transaction, exception row in query_log, quota), as TCPHandler and evaluatePollDescriptor already do. Each pulling executor now lives in an inner scope, so it is still destroyed before onFinish releases the memory reservation. Measured with memory-tracker fault injection (p = 0.002) in a named session with implicit_transaction = 1, probing transactionID() after every failed call, 2500 calls per RPC: with the previous commit 312 of 2708 faults left a running transaction in the session, 250 of them onFinish faults; with this one 225 onFinish faults left none. The other leaks, 62 and 73 in the two runs, come from a fault in the BlockIO move-assignment inside executeQuery itself (QueryPlanResourceHolder::append allocates), before any handler owns the BlockIO; that is not Arrow Flight code and affects every protocol. For the same reason no transaction case is added to the test: there is no deterministic way to make onFinish throw, and under random fault injection that other path would make it flaky. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 16 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 6b345f1Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261104-130007 |
|
@vitlibar can you give a quick review? |
Resolve the conflict in ArrowFlightServer.cpp: 26.10 does not have #125534 (the `block.empty()` check in `DoGet`), so that check is left out and only #129193's lines are kept. Leave out 05497_arrowflight_exception_on_query_finish: 26.10 has no Arrow Flight port in the stateless test config (#125517 is master-only), so the test cannot connect there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflicts in ArrowFlightServer.cpp: 26.9 does not have #115250, #125534 and #125553, which changed the same lines (conversion settings, the `block.empty()` check in `DoGet`, `removeSpecialColumnRepresentations`), so their changes are left out and only #129193's lines are kept. Leave out 05497_arrowflight_exception_on_query_finish: 26.9 has no Arrow Flight port in the stateless test config (#125517 is master-only), so the test cannot connect there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflicts in ArrowFlightServer.cpp: 26.8 does not have #115250, #125534 and #125553, which changed the same lines (conversion settings, the `block.empty()` check in `DoGet`, `removeSpecialColumnRepresentations`), so their changes are left out and only #129193's lines are kept. Leave out 05497_arrowflight_exception_on_query_finish: 26.8 has no Arrow Flight port in the stateless test config (#125517 is master-only), so the test cannot connect there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #129193 to 26.8: Fix server abort when an Arrow Flight query throws while finishing
… throws while finishing
Cherry pick #129193 to 26.9: Fix server abort when an Arrow Flight query throws while finishing
… throws while finishing
Cherry pick #129193 to 26.10: Fix server abort when an Arrow Flight query throws while finishing
…y throws while finishing
Backport #129193 to 26.8: Fix server abort when an Arrow Flight query throws while finishing
Backport #129193 to 26.9: Fix server abort when an Arrow Flight query throws while finishing
Backport #129193 to 26.10: Fix server abort when an Arrow Flight query throws while finishing
Related: #91170
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server crash (
std::terminate) when an Arrow Flight call (DoPut,DoGet,GetFlightInfo,GetSchema) failed while finishing its query, for example withMEMORY_LIMIT_EXCEEDED. The call now returns an error to the client.Description
Stress test (arm_release) on master a8e6d0bf aborted with
Terminate called for uncaught exception: Code: 241 ... fault injected (MEMORY_LIMIT_EXCEEDED), thrown fromBlockIO::onFinishinside theSCOPE_EXITofArrowFlightServer::DoPut. The stress test sends queries through Arrow Flight since #125517.Four handlers (
DoPut,DoGet,GetSchema, andexecuteSQLtoTables_implused byGetFlightInfo) finished the query from a scope guard, so on successonFinishran in a destructor. It allocates through memory-tracked containers (processors profile, pipeline printing), and on a normal scope exit the memory tracker may throw. An exception leaving a destructor terminates the server. On v26.8 LTS and v26.10, an Arrow Flight call whose finish step throws, for example on a memory limit, aborts the server.onFinishis now the last step of the worktry, after the executor's scope, so a throw from it goes to the existingcatchandonException, as inTCPHandlerandevaluatePollDescriptor: an implicit transaction is rolled back and the exception is logged. The guard keeps onlyonCancelOrConnectionLoss. The exception reachestryRunAndLogIfError, and the client gets an error status.The new test loops all four calls in a Flight session with
memory_tracker_fault_probability. The unfixed server aborted in 25/25 runs (median 14-42 iterations per call type; every trace hasonFinishand the guard). The fixed one returned all 225 faults insideonFinishover 10000 calls as errors, in a named session withimplicit_transaction = 1, and each one rolled its transaction back (transactionID()probed after every failure). It passed 50/50 randomized runs andtest_arrowflight_interface(95 passed).Workflow [PR]
Sync PR [sync-upstream/pr/129193]
Version info
26.11.1.1470-master(included in26.11and later)