Skip to content

Cherry pick #129193 to 26.9: Fix server abort when an Arrow Flight query throws while finishing - #129633

Merged
robot-clickhouse-ci-2 merged 5 commits into
backport/26.9/129193from
cherrypick/26.9/129193
Nov 7, 2026
Merged

robot-clickhouse-ci-2 merged 5 commits into
backport/26.9/129193from
cherrypick/26.9/129193

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #129193

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits November 4, 2026 07:04
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 (#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]>
…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]>
…pe-exit

Fix server abort when an Arrow Flight query throws while finishing
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 5, 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]>
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

The conflicts are in ArrowFlightServer.cpp, where master also has #115250 (conversion settings), #125534 (the block.empty() check in DoGet) and #125553 (removeSpecialColumnRepresentations). None of them is on 26.9, so I kept the 26.9 side of those lines and applied #129193's change (the guard, the onFinish calls and the inner scope) around them. Against backport/26.9/129193 the merge changes only ArrowFlightServer.cpp.

I left out the test 05497_arrowflight_exception_on_query_finish: 26.9 has no Arrow Flight port in the stateless test config (it came with #125517, which is master-only), so the test cannot connect there. Locally, with the port configured, it fails on the 26.9 tree without the change (the server aborts) and passes 20 of 20 with it (clang-22, debug).

I cannot push to cherrypick/26.9/129193. The merge is on my fork and its first parent is this PR's head 33670890ff76, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git resolve-26.9-cherrypick-129193
git push origin FETCH_HEAD:cherrypick/26.9/129193

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks @groeneai. I reviewed your merge and pushed it to cherrypick/26.9/129193 as a fast-forward (326d3678d8e1). Against backport/26.9/129193 it changes only src/Server/ArrowFlight/ArrowFlightServer.cpp. It makes the same change as #129193: onFinish is called inside the try after the executor scope closes, and the SCOPE_EXIT only calls onCancelOrConnectionLoss. It does this in executeSQLtoTables_impl, GetSchema, DoGet and DoPut, using the 26.9 conversion-settings code. A -fsyntax-only compile of the file against the 26.9 tree passes. I agree with leaving out 05497_arrowflight_exception_on_query_finish, because 26.9 has no Arrow Flight port in the stateless test config.

@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit 7aebdac into backport/26.9/129193 Nov 7, 2026
2 checks passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/26.9/129193 branch November 7, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants