Fix Arrow query parameter memory leak - #853
Draft
mlafeldt wants to merge 1 commit into
Draft
Conversation
Since a141084, every RecordBatch passed to ArrowVTab was retained for the process lifetime so stored views stayed safe to rebind. Any loop that built parameters per batch leaked without bound. Replace the three arrow_*_to_query_params helpers with ArrowBatchRegistration, which releases its batch on drop. Callers borrow the registration, making the lifetime change a compile-time break. A query that already bound the batch owns a cheap clone and may outlive the registration. Batches now live in a keyed store rather than behind a raw address, so the table function takes a single opaque UBIGINT ID and the layout marker that guarded the pointer dereference is gone. Seed the ID counter from the standard library RandomState: its random keys suit collision reduction with a view persisted by an earlier process, without promising uniform output or authorization. Reserved endpoints are clamped and exhaustion stays checked, so an ID is never reused within a store. Drop a removed batch after the store's mutex guard ends, so a foreign release callback can register or release other batches without deadlocking. DuckDB rejects mismatched argument counts and types before invoking the bind callback, so only the reachable null and unknown-ID checks remain.
mlafeldt
force-pushed
the
fix/arrow-param-memory-retention
branch
from
September 9, 2026 13:44
7d87842 to
c092925
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since a141084, every
RecordBatchpassed toArrowVTabis retained for the process lifetime so stored views stay safe to rebind. Any loop that builds parameters per batch leaks without bound.Replace the three
arrow_*_to_query_paramshelpers withArrowBatchRegistration, which releases its batch on drop. Callers borrow the registration, making the lifetime change a compile-time break. A query that already bound the batch owns a cheap clone and may outlive the registration.Following #852