Skip to content

fix(bindings/go): return available bytes from Reader.Read - #8260

Open
ClSlaid wants to merge 1 commit into
apache:mainfrom
ClSlaid:codex/go-reader
Open

fix(bindings/go): return available bytes from Reader.Read#8260
ClSlaid wants to merge 1 commit into
apache:mainfrom
ClSlaid:codex/go-reader

Conversation

@ClSlaid

@ClSlaid ClSlaid commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #8249.

Rationale for this change

Reader.Read repeats native reads until the caller buffer is full, EOF occurs, or an error occurs. This can delay bytes that storage has already returned.

For example, storage returns 3 bytes and the next read blocks. With a 1 MiB caller buffer, the current implementation withholds those 3 bytes. This change returns them before the next native read.

What changes are included in this PR?

  • Return after one native read.
  • Preserve the empty-buffer result and convert a successful zero-byte native read to io.EOF.
  • Add regression tests for available bytes, delayed errors, short reads, io.Copy, io.ReadFull, Seek, and Close.
  • Use io.ReadFull in behavior tests that require a complete buffer.
  • Update the API documentation and reader example.

Are there any user-facing changes?

Reader.Read can return fewer bytes than the buffer can hold, even before EOF. Callers must process the returned bytes before they check the error.

Callers that need a complete buffer must use io.ReadFull. If a later native read fails, the next Read call returns that error.

Validation

  • Regression tests block the second native read. The first 3 bytes reach the caller with both 8-byte and 1 MiB buffers.
  • The available-byte and delayed-error tests fail on the base revision (b6cf44f7) and pass with this change.
  • Unit tests, race tests, go vet, and golangci-lint v2.12.2 passed.
  • Existing filesystem Reader, ReaderSeek, ReaderWithConcurrentChunkGap, and IOCopy behavior tests passed with a locally built C library.
  • The guide example compiled for Linux amd64 with CGO disabled.

AI Usage Statement

AI assisted the implementation, regression tests, and documentation. The latency regression tests control the native read results. Actual network latency remains unmeasured.

@ClSlaid
ClSlaid marked this pull request as ready for review September 8, 2026 09:09
@Xuanwo

Xuanwo commented Sep 8, 2026

Copy link
Copy Markdown
Member

Is this change valid compared with go's semantic?

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.

new feature: let Go Reader return available bytes without filling every caller buffer

2 participants