Repository navigation
AWS: Fix zero-length S3 tail reads - #18329
Conversation
Skip empty positional and tail reads after validating the buffer so S3 never receives invalid or unsatisfiable ranges. Generated-by: Codex (GPT-6)
|
@pingedbrain, could you please review it when you have some time? |
The early return guarantees a positive read length before read metrics are updated. Generated-by: Codex (GPT-6)
|
Would it be worth adding a small RustFS integration test for this case? I ran this locally against RustFS 1.0.0 with a missing object: readFully(0, buffer, 1, 0) On main, the first call sends The unit test covers the mocked client; an integration test would keep this provider-level regression covered. |
Generated-by: Codex (GPT-6)
|
@AlejandroMorgante can you explain what motivated this PR? This is a little surprising because we're changing the contract for readers under the impression that there's an optimization to be had here. Was this something that was just identified or is there a practical case that this impacts? |
|
Our processes use Iceberg’s RangeReadable interface with dynamically computed ranges. During testing, a computed tail length was zero. I checked Avoiding an unnecessary S3 I think zero-length reads should be no-ops: |
Generated-by: Codex (GPT-6)
|
My higher-level concern is that we're making an optimization that subtly changes the contract behavior. We bypass permissions checks and the underlying SDK doesn't do that, which is why we see the zero byte request pass through. I don't feel like this would cause problems, but at the same time I feel like it's a narrow optimization case that makes things a little more complicated. It sounds like the original problem was that we produced an invalid object range. Alternatively, we could maintain the full IO contract at just fix that issue. |
|
I agree that returning early bypasses the existence and permission checks performed by S3. However, from a caller’s perspective, it seems surprising for a zero-length read to fail with an |
Limit the fix to a valid tail range while retaining GetObject validation and restoring readFully behavior. Generated-by: Codex
|
@danielcweeks I updated the PR to preserve the I/O behavior you pointed out. For Behavior of
I validated the original RustFS integration tests also passed for empty, nonempty, and missing objects. Permission-error propagation also passed against real S3: a temporary STS session denying What do you think of this approach? Does it address your concern about preserving the I/O contract? |
Generated-by: Codex
|
@AlejandroMorgante sorry this fell of my radar. Unfortunately, I don't like the 1-byte workaround since that changes the read contract in a strange way. If we can't issue a zero byte read, then I think I would prefer just returning (it's the lesser of two evils here). However, I wouldn't change the other paths since we're just delegating to the SDK. |
Avoid invalid zero-length suffix ranges without requesting an extra byte. Leave readFully behavior unchanged. Generated-by: Codex
|
@danielcweeks Thanks! Updated |
danielcweeks
left a comment
There was a problem hiding this comment.
Thanks @AlejandroMorgante, this is a much narrower and cleaner fix!
S3InputStream.readTail(..., 0)constructsRange: bytes=-0, which fails withInvalidRange. Return0immediately after buffer validation when the requested length is zero, without changing the buffer or issuing an S3 request.readFullyand nonzero tail reads retain their existing behavior.Test plan: verify the zero return value, unchanged buffer, and absence of S3 calls; cover empty, nonempty, and missing objects in integration tests, and retain stream-closure coverage for nonzero reads. The
S3InputStreamunit and integration test classes,spotlessApply, AWScheckstyleMain, andcheckstyleTestpassed with Java 17.Validated commit
653c5ce7bagainst real Amazon S3: zero-length tail reads returned0without changing the buffer for 0-byte, 1-byte, and 5-MiB objects and a missing object. NonzeroreadTailandreadFullyreads returned the expected data; a nonzero tail read of the missing object propagatedNoSuchKeyException. The temporary bucket and objects were deleted.AI Disclosure