Skip to content

fix: don't signal onComplete when a chunk is fully consumed by the ra… - #523

Merged
sharmabikram merged 4 commits into
mainfrom
shbikram/adjustedrange-premature-oncomplete
Oct 1, 2026
Merged

sharmabikram merged 4 commits into
mainfrom
shbikram/adjustedrange-premature-oncomplete

Conversation

@sharmabikram

Copy link
Copy Markdown
Contributor

Consume the chunk toward the skip and return instead of completing; the real onComplete still fires when upstream ends. Changed > to >= so a chunk equal to the skip is also fully consumed. Fixes #517.

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Check any applicable:

  • Were any files moved? Moving files changes their URL, which breaks all hyperlinks to the files.

@sharmabikram
sharmabikram requested a review from a team as a code owner September 24, 2026 21:02
// rather than signaling completion.
numBytesToSkip -= buf.length;
wrappedSubscriber.onComplete();
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure we still need to signal something to the subscriber. I don't know what it would be but it feels really weird that we would go from telling the subscriber "done" to not telling the subscriber anything.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe signal wrappedSubscriber's onNext with an empty buffer? Since that's really what's going on here

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern. Should we just do .onComplete() and return and wait for the next turn instead of signaling it here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the PR with onNext. Can you please refer to the latest diff?

…nge skip

AdjustedRangeSubscriber called onComplete (and fell through to an NPE) when
numBytesToSkip exceeded a chunk, so a small first chunk ended ranged GETs
with an empty stream. Consume the chunk toward the skip and wait for the
next one instead. Fixes #517.
@sharmabikram
sharmabikram force-pushed the shbikram/adjustedrange-premature-oncomplete branch from f9fb658 to 4bb8003 Compare September 26, 2026 23:03
The existing coverage exercises ranged GETs over real transport, which only
intermittently produces a first chunk smaller than the skip, so it cannot
deterministically catch the premature-onComplete bug (#517). RangedGetUtilsTest
covers only the range string math and never drives the subscriber.

Add tests that wire the real production topology in-JVM -- a backpressure-
honoring publisher feeding AdjustedRangeSubscriber wrapping the real
InputStreamSubscriber (as toBlockingInputStream uses) -- and assert the full
in-range payload is delivered when the first chunk is smaller than, empty, or
exactly equal to the skip. Each read is bounded by a timeout so a demand stall
fails fast instead of hanging. These fail on the pre-fix code (empty stream)
and pass with the fix. No AWS credentials required; runs in the normal test
phase.
Drop editorializing ("REAL", issue references) from the javadoc in favor of
plain descriptions of the topology and each case.
@sharmabikram
sharmabikram marked this pull request as draft September 30, 2026 20:52
Shorten the skip-branch comment and the test comments to one-liners, remove
issue references, and drop narration that just restates the adjacent code.
@sharmabikram
sharmabikram marked this pull request as ready for review September 30, 2026 21:47
@Override
public void onNext(ByteBuffer byteBuffer) {
if (virtualAvailable <= 0) {
wrappedSubscriber.onComplete();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not blocking) We probably should also return here so that onComplete doesn't get called twice. But it's not producing the kind of problem that we want to fix.

@josecorella josecorella left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@sharmabikram
sharmabikram merged commit 199bbb5 into main Oct 1, 2026
35 of 36 checks passed
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.

Ranged GET can return an empty stream: AdjustedRangeSubscriber prematurely signals onComplete when the first chunk is smaller than the pending skip

4 participants