Skip to content

branch-4.0: [fix](arrow-flight-sql) Close temporary VectorSchemaRoot in createPreparedStatement to fix FE direct memory leak #65311 - #66431

Merged
morningman merged 1 commit into
branch-4.0from
auto-pick-65311-branch-4.0
Aug 5, 2026
Merged

branch-4.0: [fix](arrow-flight-sql) Close temporary VectorSchemaRoot in createPreparedStatement to fix FE direct memory leak #65311#66431
morningman merged 1 commit into
branch-4.0from
auto-pick-65311-branch-4.0

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Cherry-picked from #65311

@github-actions
github-actions Bot requested a review from morningman as a code owner August 4, 2026 08:39
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 83.33% (5/6) 🎉
Increment coverage report
Complete coverage report

…paredStatement to fix FE direct memory leak (#65311)

```
### What problem does this PR solve?

Issue Number: close #65305

Problem Summary:

`DorisFlightSqlProducer#createPreparedStatement` creates two `VectorSchemaRoot`
instances (an empty one for the parameter schema, and one from
`FlightSqlChannel#createOneOneSchemaRoot(...)` for the result metadata),
extracts only their `Schema`, and never closes them.

`createOneOneSchemaRoot` allocates a `VarCharVector` from the channel
`RootAllocator` (off-heap, Netty pooled direct buffer). Since the returned
`VectorSchemaRoot` is never closed, its off-heap buffer is leaked on every
prepare call (effectively every Arrow Flight query, because ADBC prepares each
statement). The buffer cannot be reclaimed by GC (strongly referenced by the
allocator) nor by closing the client session (`FlightSqlChannel#close()` only
invalidates the result cache and does not close the allocator; the leaked root
is never stored in any session map).

Under continuous Arrow Flight query load this makes FE direct memory grow
monotonically until:
`java.lang.OutOfMemoryError: Cannot reserve ... bytes of direct buffer memory (Internal; Prepare)`

This PR wraps both temporary roots in try-with-resources so their off-heap
buffers are released after the `Schema` is extracted. `Schema` is an immutable
POJO and remains valid after the root is closed. Compare with
`getCatalogs`/`getSchemas`/`getTables` in the same producer, which already use
try-with-resources.

---------

Signed-off-by: 柳吟风 <523684989@qq.com>
Signed-off-by: morningman <yunyou@selectdb.com>
Co-authored-by: 柳吟风 <523684989@qq.com>
Co-authored-by: morningman <yunyou@selectdb.com>
@yiguolei
yiguolei force-pushed the auto-pick-65311-branch-4.0 branch from 526b23b to 73fbbbe Compare August 4, 2026 13:38
@yiguolei

yiguolei commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 23.81% (5/21) 🎉
Increment coverage report
Complete coverage report

@morningman
morningman merged commit 99ef194 into branch-4.0 Aug 5, 2026
30 of 34 checks passed
@github-actions
github-actions Bot deleted the auto-pick-65311-branch-4.0 branch August 5, 2026 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants