Skip to content

fix(arrow/flight/flightsql): avoid double-retaining parameter readers - #1066

Open
fallintoplace wants to merge 3 commits into
apache:mainfrom
fallintoplace:fix/flightsql-record-reader-retain
Open

fix(arrow/flight/flightsql): avoid double-retaining parameter readers#1066
fallintoplace wants to merge 3 commits into
apache:mainfrom
fallintoplace:fix/flightsql-record-reader-retain

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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

@fallintoplace
fallintoplace requested a review from zeroshade as a code owner July 29, 2026 21:58

@serramatutu serramatutu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ref counting is the way for this. Also, can you add a test to repro the specific bug you're trying to fix?

Comment thread arrow/flight/flightsql/client_test.go Outdated
mock.Mock
}

type referenceCountingReader struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ref counting mechanism is used only in one place and is not a widespread architectural pattern. To me this is a signal that this is a workaround for a bug instead of an actual good fix.

I think the proper solution for readers is ensuring we do lifecycle management right (i.e call Retain() in the right places) instead of adding ref counting.

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.

2 participants