Skip to content

Fix server abort when an Arrow Flight query throws while finishing - #129193

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-arrowflight-onfinish-scope-exit
Nov 5, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-arrowflight-onfinish-scope-exit

Conversation

@groeneai

@groeneai groeneai commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #91170

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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 with MEMORY_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 from BlockIO::onFinish inside the SCOPE_EXIT of ArrowFlightServer::DoPut. The stress test sends queries through Arrow Flight since #125517.

Four handlers (DoPut, DoGet, GetSchema, and executeSQLtoTables_impl used by GetFlightInfo) finished the query from a scope guard, so on success onFinish ran 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.

onFinish is now the last step of the work try, after the executor's scope, so a throw from it goes to the existing catch and onException, as in TCPHandler and evaluatePollDescriptor: an implicit transaction is rolled back and the exception is logged. The guard keeps only onCancelOrConnectionLoss. The exception reaches tryRunAndLogIfError, 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 has onFinish and the guard). The fixed one returned all 225 faults inside onFinish over 10000 calls as errors, in a named session with implicit_transaction = 1, and each one rolled its transaction back (transactionID() probed after every failure). It passed 50/50 randomized runs and test_arrowflight_interface (95 passed).


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

Version info

  • Merged into: 26.11.1.1470-master (included in 26.11 and later)

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]>
@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
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).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test's counters cover all four calls together, so it may not prove each handler's finish error DISAGREE Each iteration runs all four calls, so reverting the fix at any one site aborts the server. Unfixed, one call type per loop: 20/20 runs aborted within 95 iterations (cap 200), every trace at that handler's guard. Fixed: 198 faults inside onFinish, spread over all four handlers, came back as errors. A finish-only fault would need a new failpoint in src/.
2 💡 Use Critical Bug Fix for a server abort DISAGREE Bug Fix: the abort is reachable on v26.8 LTS and v26.10 stable through the documented Arrow Flight interface.
3 💡 Runtime vs a long tag DISAGREE 8.3 s on debug, at most 5.3 s per run under -j 8.
4 💡 If onFinish throws, the query gets no finish or exception row in query_log DISAGREE Same as BlockIO::executeWithCallbacks. Today the server aborts instead.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261104-070900

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Looping one Arrow Flight call on SELECT 1 in a session with memory_tracker_fault_probability = 0.002, max_untracked_memory = 0 aborted the unfixed server in 25/25 runs (5 per call type: DoPut, DoGet, GetFlightInfo, GetSchema, all four), median 14-42 iterations.
b Root cause explained? BlockIO::onFinish ran inside a SCOPE_EXIT (a destructor) on success. It allocates through memory-tracked containers that may throw MEMORY_LIMIT_EXCEEDED on a normal scope exit, and an exception leaving a destructor calls std::terminate.
c Fix matches root cause? Yes. onFinish runs on the normal path after the try/catch (the BlockIO::executeWithCallbacks shape); the guard keeps only onCancelOrConnectionLoss. No try/catch wrapper, nothing swallowed: the exception reaches tryRunAndLogIfError and becomes an error status.
d Test intent preserved / new tests added? New 05497_arrowflight_exception_on_query_finish.sh: all four calls under fault injection, the server must answer afterwards.
e Both directions demonstrated? Unfixed: 31/31 aborts, each system.crash_log trace has BlockIO::onFinish and the handler's guard; the new test FAILs (server aborted). Fixed: 5000 iterations, 198 faults inside onFinish returned as errors, 0 aborts; the test passes 50/50 with random settings.
f Fix is general across code paths? All four guard sites are fixed (GetFlightInfo and DoAction share executeSQLtoTables_impl). PollFlightInfo's guard only cancels; the poll-session paths already call onFinish inside try/catch. No other SCOPE_EXIT in src/ calls onFinish.
g Fix generalizes across inputs (params/datatypes/wrappers)? The failure is in query finishing, not in data conversion, so it does not depend on types. Covered: push and pull pipelines in DoPut, Flight SQL commands, DoGet, GetFlightInfo, GetSchema.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, protocol or format change; successful calls return the same data and the same Flight SQL record_count (checked on both binaries).
i Invariants and contracts preserved? The executor over the pipeline is still destroyed before onFinish (it releases the memory reservation the executor's spill state points to). onFinish runs at most once. If it throws, the guard cancels the pipeline and releases workload resources before ~BlockIO. Early returns and the catch path are unchanged.

Session id: cron:clickhouse-impl-slot-6:20261104-063000

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @yakov-olkhovskiy @vitlibar, could you review this and add the can be tested label so CI runs? The four Arrow Flight handlers called BlockIO::onFinish from a SCOPE_EXIT, so a MEMORY_LIMIT_EXCEEDED thrown while finishing escaped a destructor and aborted the server; onFinish now runs on the normal path after the try/catch, and the guard only cancels.

@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6e80da0]

Summary: ✅


AI Review

Summary

Moves BlockIO::onFinish out of scope-guard destructors in four Arrow Flight execution paths, allowing finish exceptions to return an RPC error. Executor destruction still precedes pipeline finalization, and finish failures now reach onException. The previous implicit-transaction finding is fixed at all four sites. No remaining actionable findings.

Missing context / blind spots
  • ⚠️ Current merge-head CI is still running, and no local build was available for a runtime rerun. The targeted regression report confirms 50/50 passes on the preceding revision containing the fix; completed current-head CI would close this remaining validation gap.
Final Verdict

Status: ✅ Approve. No code changes requested and no new inline findings to post. The existing bot-authored thread correctly remains resolved.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-arrow-flight labels Nov 4, 2026
…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]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6e80da019 with master bdbd1b837 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of b02fbee24; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 16 s compile time in total, 7 of them have a recent master baseline.

Job report

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6b345f1

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (arm_binary, 2/4) / test_read_temporary_tables_on_failure/test.py::test_different_versions not from this PR (it changes only the Arrow Flight handlers): the test failed 89 times on master between 2026-11-03 22:57 and 2026-11-04 11:25 UTC. Its fix merged at 12:34 UTC, after this run #129151 (mine, merged)
Mergeable Check, PR praktika rollups of the row above #129151 (mine, merged)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261104-130007

@Algunenano Algunenano added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 4, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@vitlibar can you give a quick review?

@alexey-milovidov alexey-milovidov self-assigned this Nov 5, 2026
@alexey-milovidov alexey-milovidov added the blocker This issue / pr blocks a new release label Nov 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 5, 2026
Merged via the queue into ClickHouse:master with commit 3367089 Nov 5, 2026
185 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 5, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 5, 2026
alexey-milovidov pushed a commit that referenced this pull request Nov 7, 2026
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]>
alexey-milovidov pushed a commit that referenced this pull request Nov 7, 2026
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]>
alexey-milovidov pushed a commit that referenced this pull request Nov 7, 2026
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]>
robot-clickhouse-ci-2 added a commit that referenced this pull request Nov 7, 2026
Cherry pick #129193 to 26.8: Fix server abort when an Arrow Flight query throws while finishing
robot-clickhouse added a commit that referenced this pull request Nov 7, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Nov 7, 2026
Cherry pick #129193 to 26.9: Fix server abort when an Arrow Flight query throws while finishing
robot-clickhouse added a commit that referenced this pull request Nov 7, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Nov 7, 2026
Cherry pick #129193 to 26.10: Fix server abort when an Arrow Flight query throws while finishing
robot-clickhouse added a commit that referenced this pull request Nov 7, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 7, 2026
Backport #129193 to 26.8: Fix server abort when an Arrow Flight query throws while finishing
clickhouse-gh Bot added a commit that referenced this pull request Nov 7, 2026
Backport #129193 to 26.9: Fix server abort when an Arrow Flight query throws while finishing
clickhouse-gh Bot added a commit that referenced this pull request Nov 7, 2026
Backport #129193 to 26.10: Fix server abort when an Arrow Flight query throws while finishing
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 7, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-arrow-flight-protocol Apache Arrow Flight server interface: ClickHouse as a Flight server on its own port (gRPC-based d... label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release can be tested Allows running workflows for external contributors comp-arrow-flight-protocol Apache Arrow Flight server interface: ClickHouse as a Flight server on its own port (gRPC-based d... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

6 participants