THRIFT-6144: Report EOF when Ruby transport reads make no progress - #3708
Open
kpumuk wants to merge 1 commit into
Open
THRIFT-6144: Report EOF when Ruby transport reads make no progress#3708kpumuk wants to merge 1 commit into
kpumuk wants to merge 1 commit into
Conversation
Client: rb Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Thrift::BaseTransport#read_all in the Ruby library to properly detect end-of-input when the underlying transport returns nil or an empty string, avoiding both a leaked NoMethodError and an infinite retry loop when reads make no progress.
Changes:
- Treat
niland empty-string reads asTransportException::END_OF_FILEwhen additional bytes are still required. - Preserve existing behavior for
size == 0(return an empty binary buffer without callingread) and for partial progress (continue accumulating while each read returns data). - Add spec coverage for EOF-on-no-progress cases, plus frozen first-chunk behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/rb/lib/thrift/transport/base_transport.rb | Updates read_all to raise END_OF_FILE on nil/empty reads and to only accumulate while reads make progress (also ensures appended chunks are forced to binary). |
| lib/rb/spec/base_transport_spec.rb | Adds focused tests covering empty/nil reads, progress behavior, frozen first chunk handling, and the zero-size read fast path. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Ruby transports may report end of input by returning
nilor an empty string.BaseTransport#read_allcurrently leaks a RubyNoMethodErrorfornil, while an empty result causes it to retry forever without making progress.This change treats either result as
TransportException::END_OF_FILEwhen bytes are still required. Partial reads continue normally while each call makes progress, and zero-size reads still return an empty binary string without invoking the underlying transport.The common path returns a complete first chunk directly. A short frozen chunk is copied only when it must become the accumulator for subsequent reads.
Benchmarks
The common exact-read path was measured in the dedicated Ruby container using Ruby 4.0.6 on aarch64 Linux. A temporary stdlib benchmark used a
BaseTransportwhosereadmethod returned a frozen eight-byte binary string, with 1,000,000 warmup calls followed by seven trials of 5,000,000 calls:bundle exec ruby -Ilib /tmp/rb-read-all-benchmark.rbc2def39207a73394420088da9b4b105571dd9036: median 6,406,402 operations/secondThis deliberately removes all underlying I/O and therefore magnifies the cost of the EOF and progress checks. Network, file, and layered transports should spend most of their time in the underlying read. Returning a complete first chunk directly avoids the allocation and copy that an intermediate accumulator would otherwise add.
[skip ci]anywhere in the commit message to free up build resources.