Repository navigation
fix(go/adbc/sqldriver): return owned copies of string/binary values - #4625
Merged
Merged
Conversation
array.String.Value (and LargeString/Binary/LargeBinary) returns a value that aliases the Arrow data buffer (zero-copy). rows.Next handed those straight to database/sql, which retains driver.Values after Next returns and after the underlying record batch is released. For ADBC results the record's buffers are C-owned, so once the batch is released the value reads back as garbage. Copy string/binary values into Go-owned memory before returning them so they outlive the batch. Surfaced by the arrow-go v18.7 bump, which changed buffer release timing enough to make the latent aliasing fatal; the zero-copy return predates it. Signed-off-by: iremcaginyurtturk <[email protected]>
lidavidm
approved these changes
Jul 29, 2026
Fixes the golangci-lint SA1019 failure (array.NewRecord is deprecated). Signed-off-by: iremcaginyurtturk <[email protected]>
Contributor
Author
|
Hi @lidavidm 🙏 I’m blocked downstream by this fix. Could you approve the CI run and take a quick look when you have a moment? |
Member
|
Hi @iremcaginyurtturk, I approved CI and @lidavidm can merge later today. Will you be unblocked after merge or do you need a new release to pick up this fix? |
Contributor
Author
amoeba
approved these changes
Jul 29, 2026
Member
|
Merged, thanks! |
iremcaginyurtturk
added a commit
to bruin-data/ingestr
that referenced
this pull request
Jul 29, 2026
Pins github.com/apache/arrow-adbc/go/adbc to the merged commit of apache/arrow-adbc#4625, which fixes the zero-copy string/binary values returned by the sqldriver. Under arrow-go v18.7 (required transitively by the iceberg-go pin) those aliased the freed Arrow buffer and read back as garbage, breaking every DuckDB/ADBC read (SchemaEvolution, CDC merge, stress convergence, ...). Regenerate licenses.lock.yml for the bump.
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.
Problem
rows.Nextreturnedarray.String.Value(andLargeString/Binary/LargeBinary) directly as thedriver.Value. Those are zero-copy values that alias the underlying Arrow data buffer.database/sqlretains thedriver.Values afterNextreturns — and after the underlying record batch (and its buffer) is released. For ADBC results the batch buffers are C-owned, so once the batch is released the value reads back as garbage.Minimal reproduction: reading a
VARCHARfrom a DuckDB ADBC query through thissqldriverreturns a corrupted string (e.g."\xb6|:u\x14\x7f\x00", stale memory) instead of the actual text. Reading the same result directly at the Arrow level (before release) is correct, which localizes the problem torows.Nexthanding back an alias rather than an owned value.What changed
Copy string/binary values into Go-owned memory (
strings.Clone/bytes.Clone) so they outlive the record batch.Why it surfaced now
The zero-copy return predates this (it's been in
rows.Nextsince the originaldatabase/sqlwrapper, #97). It was surfaced by the arrow-go v18.7 bump — specifically apache/arrow-go#793, which replaced thenativeCRecordBatchReaderfinalizer with deterministic atomic Retain/Release. C memory is now freed promptly when the batch is released instead of lazily at GC, so the latent aliasing became a use-after-free.