Skip to content

fix(layers/retry): do not reopen a read once the range is exhausted - #8343

Open
swanandx wants to merge 1 commit into
apache:mainfrom
swanandx:fix-retry-reopen-at-eof
Open

swanandx wants to merge 1 commit into
apache:mainfrom
swanandx:fix-retry-reopen-at-eof

Conversation

@swanandx

Copy link
Copy Markdown

When a stream breaks after its last byte, the layer advances the range to size zero and reopens with it. Nothing is left to fetch, and an empty range has no valid Range header.

Return an empty buffer instead, which callers treat as end of stream.

An unbounded read has no size to compare against, so it still reopens past the end. Catching that needs the object size.

Which issue does this PR close?

Closes #8342

Rationale for this change

RetryReadStream::read advances the range by what it has read before reopening. If the stream breaks after the last byte, the range is already empty by then, and it reopens with it. Nothing is left to fetch.

With a LoggingLayer in the stack that panics, because the layer calls to_string() on the range and Display returns Err for a zero size. ErrorContextLayer does the same on its error path. Without either, the request goes out with an empty Range header.

What changes are included in this PR?

Return an empty buffer instead of reopening. Callers already treat that as end of stream; the trait's own read_all does (core/core/src/raw/oio/read/api.rs:119).

This covers bounded ranges and suffixes. An unbounded read has no size to compare against, so it still reopens past the end. Catching that needs the object size.

Adds a test that fails without the guard. test_retry_read reads unbounded, so it still reopens and still expects five attempts. It is unchanged.

Are there any user-facing changes?

Don't think so

Breaking changes

No

AI Usage Statement

  • Harness: Claude Code
  • Model: Claude Opus 5
  • Effort: default; the harness does not surface a setting
  • Role: helped trace the reopen path and draft the test.

When a stream breaks after its last byte, the layer advances the range to size
zero and reopens with it. Nothing is left to fetch, and an empty range has no
valid Range header.

Return an empty buffer instead, which callers treat as end of stream.

An unbounded read has no size to compare against, so it still reopens past the
end. Catching that needs the object size.
@swanandx
swanandx requested a review from Xuanwo as a code owner September 24, 2026 22:27
@github-actions github-actions Bot added core releases-note/fix The PR fixes a bug or has a title that begins with "fix" size:M This PR changes 30-99 lines, ignoring generated files. labels Sep 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core releases-note/fix The PR fixes a bug or has a title that begins with "fix" size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: read reopens with a zero-size range after the last byte

1 participant