This is an automated email from the ASF dual-hosted git repository.

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 3e24c767 fix(arrow/flight/flightsql): avoid double-retaining parameter 
readers (#1066)
3e24c767 is described below

commit 3e24c76741c240cce1dbd6de1c102bd42ed9a00e
Author: Minh Vu <[email protected]>
AuthorDate: Wed Aug 5 19:49:12 2026 +0200

    fix(arrow/flight/flightsql): avoid double-retaining parameter readers 
(#1066)
    
    ## What changed
    
    Remove the duplicate retain in `PreparedStatement.SetRecordReader`.
    
    ## Why
    
    The setter retained the supplied reader twice, while parameter
    replacement and statement close released it only once. This left one
    reference permanently owned by the statement.
    
    The regression test binds an allocator-backed record reader, drops the
    caller-owned references, then replaces the binding. The statement's
    single release must free the record buffers; the previous double retain
    leaves them allocated.
    
    ## Testing
    
    - `go test ./arrow/flight/flightsql`
    - `go test -race ./arrow/flight/flightsql -run
    TestPreparedStatementReleasesRecordReaderBindingOnce`
---
 arrow/flight/flightsql/client.go                   |  1 -
 .../prepared_statement_reader_lifecycle_test.go    | 52 ++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/arrow/flight/flightsql/client.go b/arrow/flight/flightsql/client.go
index e76b4163..aca4cbf7 100644
--- a/arrow/flight/flightsql/client.go
+++ b/arrow/flight/flightsql/client.go
@@ -1422,7 +1422,6 @@ func (p *PreparedStatement) SetParameters(binding 
arrow.RecordBatch) {
 // PreparedStatement.
 func (p *PreparedStatement) SetRecordReader(binding array.RecordReader) {
        p.clearParameters()
-       binding.Retain()
        p.streamBinding = binding
        p.streamBinding.Retain()
 }
diff --git a/arrow/flight/flightsql/prepared_statement_reader_lifecycle_test.go 
b/arrow/flight/flightsql/prepared_statement_reader_lifecycle_test.go
new file mode 100644
index 00000000..3030bb76
--- /dev/null
+++ b/arrow/flight/flightsql/prepared_statement_reader_lifecycle_test.go
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package flightsql_test
+
+import (
+       "strings"
+       "testing"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/array"
+       "github.com/apache/arrow-go/v18/arrow/flight/flightsql"
+       "github.com/apache/arrow-go/v18/arrow/memory"
+       "github.com/stretchr/testify/require"
+)
+
+func TestPreparedStatementReleasesRecordReaderBindingOnce(t *testing.T) {
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       schema := arrow.NewSchema([]arrow.Field{
+               {Name: "id", Type: arrow.PrimitiveTypes.Int64, Nullable: true},
+       }, nil)
+
+       rec, _, err := array.RecordFromJSON(mem, schema, 
strings.NewReader(`[{"id": 1}]`))
+       require.NoError(t, err)
+
+       rdr, err := array.NewRecordReader(schema, []arrow.RecordBatch{rec})
+       require.NoError(t, err)
+
+       prepared := flightsql.NewPreparedStatement(&flightsql.Client{}, nil)
+       prepared.SetRecordReader(rdr)
+
+       // Drop the caller-owned references. Replacing the binding must release 
the
+       // single reference retained by the prepared statement and free the 
record.
+       rdr.Release()
+       rec.Release()
+       prepared.SetParameters(nil)
+
+       mem.AssertSize(t, 0)
+}

Reply via email to