Skip to content

THRIFT-6105: Preserve partial MemoryBufferTransport read progress#3646

Open
kpumuk wants to merge 1 commit into
apache:masterfrom
kpumuk:rb-short-destination
Open

THRIFT-6105: Preserve partial MemoryBufferTransport read progress#3646
kpumuk wants to merge 1 commit into
apache:masterfrom
kpumuk:rb-short-destination

Conversation

@kpumuk

@kpumuk kpumuk commented Jul 19, 2026

Copy link
Copy Markdown
Member

The native MemoryBufferTransport#read_into_buffer implementation delayed recording its transport position until the whole request completed. If input or destination capacity ran out after bytes had been copied, the destination contained those bytes while the transport still treated them as unread.

This change preserves the progress of successfully copied bytes before raising, so native retry and recovery behavior matches the pure-Ruby implementation.

  • Did you create an Apache Jira ticket? THRIFT-6105
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

Copilot AI review requested due to automatic review settings July 19, 2026 19:24
@mergeable mergeable Bot added the ruby Pull requests that update Ruby code label Jul 19, 2026

Copilot AI 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.

Pull request overview

This PR fixes the Ruby native extension implementation of MemoryBufferTransport#read_into_buffer so it preserves transport read progress for bytes that were successfully copied before an exception is raised. This aligns the native behavior with the pure-Ruby implementation, preventing situations where the destination buffer contains copied bytes but the transport still considers them unread.

Changes:

  • Update the native read_into_buffer loop to (a) avoid consuming input bytes when the destination is exhausted and (b) persist the updated transport index before raising EOFError/IndexError.
  • Add Ruby specs covering frozen destination buffers, zero-length reads, and partial-progress consumption semantics for both destination exhaustion and input exhaustion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/rb/spec/base_transport_spec.rb Adds regression tests for frozen buffers, zero-length reads, and partial-progress consumption behavior.
lib/rb/ext/memory_buffer.c Persists read progress before raising and avoids consuming an extra input byte when the destination is out of capacity.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Client: rb

Co-Authored-By: OpenAI Codex (GPT-5.4) <codex@openai.com>
Copilot AI review requested due to automatic review settings July 20, 2026 15:58
@kpumuk
kpumuk force-pushed the rb-short-destination branch from 40de1de to 6749ac8 Compare July 20, 2026 15:58

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +144 to 146
char byte = RSTRING_PTR(buf)[index++];
((char*)RSTRING_PTR(buffer_value))[i] = byte;
i++;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Pull requests that update Ruby code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants