Skip to content

fix(arrow): retain pools for stream buffers - #182

Merged
SteNicholas merged 1 commit into
apache:mainfrom
mrdrivingduck:codex/fix-arrow-buffer-pool-lifetime
Aug 6, 2026
Merged

fix(arrow): retain pools for stream buffers#182
SteNicholas merged 1 commit into
apache:mainfrom
mrdrivingduck:codex/fix-arrow-buffer-pool-lifetime

Conversation

@mrdrivingduck

Copy link
Copy Markdown
Contributor

I found this while debugging an S3 crash. I initially suspected the S3 filesystem, but the issue was in the Arrow input-stream adapter: a returned buffer can outlive its memory pool when a reader is closed while a caller still holds a buffer. This is more likely with network filesystems, where asynchronous reads may finish after the reader is closed.

This patch uses shared_ptr's aliasing constructor to keep the pool alive with the returned buffer. It also adds deterministic coverage for Read, ReadAt, and ReadAsync using a small InputStream mock. Without the change, the tests crash; with it, they pass.

@mrdrivingduck
mrdrivingduck marked this pull request as ready for review August 5, 2026 01:56
@mrdrivingduck
mrdrivingduck force-pushed the codex/fix-arrow-buffer-pool-lifetime branch 3 times, most recently from c430694 to b35d136 Compare August 6, 2026 03:00
return arrow::Status::OK();
}

struct BufferWithMemoryPool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could you please modify the PR title to conventional commits style, and add a TODO assigned to xinyu, noting that performance will be optimized later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done with PR title. TODO means an issue or simply cc from current PR?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add a line in code:

// TODO(lxy): xxxxxx

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in KeepMemoryPoolAlive.

@mrdrivingduck mrdrivingduck changed the title Fix memory pool lifetime for Arrow stream buffers fix(arrow): retain pools for stream buffers Aug 6, 2026
@mrdrivingduck
mrdrivingduck force-pushed the codex/fix-arrow-buffer-pool-lifetime branch from b35d136 to 4ea9719 Compare August 6, 2026 07:35
Keep Arrow memory pools alive while returned stream buffers remain
referenced and note the allocation overhead for a future performance
improvement.

Add deterministic coverage for synchronous and asynchronous reads after
adapter teardown.

Co-authored-by: GPT-5.6 Terra <codex@users.noreply.github.com>
@mrdrivingduck
mrdrivingduck force-pushed the codex/fix-arrow-buffer-pool-lifetime branch from 4ea9719 to 3f0d672 Compare August 6, 2026 08:22

@zjw1111 zjw1111 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

@SteNicholas SteNicholas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@SteNicholas
SteNicholas merged commit 3663237 into apache:main Aug 6, 2026
16 checks passed
@mrdrivingduck
mrdrivingduck deleted the codex/fix-arrow-buffer-pool-lifetime branch August 6, 2026 14:40
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.

3 participants