Skip to content

fix: return partial bytes to caller on transient S3 read error - #239

Closed
Alena0704 wants to merge 1 commit into
masterfrom
fix-retry-reader-partial-read
Closed

Alena0704 wants to merge 1 commit into
masterfrom
fix-retry-reader-partial-read

Conversation

@Alena0704

Copy link
Copy Markdown

When S3 returns n > 0 bytes alongside an error, the previous code discarded those bytes while still advancing offsetReached by n. On retry, the new S3 request started from the advanced offset, skipping the discarded bytes and delivering a mix of data from two different stream positions into the same caller buffer.

This caused block checksum mismatches in Greenplum AOCO tables stored in Yezzey/S3: the block header and its data came from non-contiguous stream positions.

Fix: when n > 0 and err != nil, return the n bytes to the caller immediately and defer the reconnect to the next Read call via needReacquire=true. This follows the io.Reader contract: if bytes were read, they must be returned even when an error also occurred.

When S3 returns n > 0 bytes alongside an error, the previous code
discarded those bytes while still advancing offsetReached by n.
On retry, the new S3 request started from the advanced offset,
skipping the discarded bytes and delivering a mix of data from two
different stream positions into the same caller buffer.

This caused block checksum mismatches in Greenplum AOCO tables
stored in Yezzey/S3: the block header and its data came from
non-contiguous stream positions.

Fix: when n > 0 and err != nil, return the n bytes to the caller
immediately and defer the reconnect to the next Read call via
needReacquire=true. This follows the io.Reader contract: if bytes
were read, they must be returned even when an error also occurred.
@Alena0704
Alena0704 requested a review from Vlasdislav October 15, 2026 12:29
@Alena0704 Alena0704 closed this Oct 15, 2026
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.

1 participant