fix: don't signal onComplete when a chunk is fully consumed by the ra… - #523
Conversation
| // rather than signaling completion. | ||
| numBytesToSkip -= buf.length; | ||
| wrappedSubscriber.onComplete(); | ||
| return; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Maybe signal wrappedSubscriber's onNext with an empty buffer? Since that's really what's going on here
There was a problem hiding this comment.
Same concern. Should we just do .onComplete() and return and wait for the next turn instead of signaling it here?
There was a problem hiding this comment.
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.
f9fb658 to
4bb8003
Compare
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.
Shorten the skip-branch comment and the test comments to one-liners, remove issue references, and drop narration that just restates the adjacent code.
| @Override | ||
| public void onNext(ByteBuffer byteBuffer) { | ||
| if (virtualAvailable <= 0) { | ||
| wrappedSubscriber.onComplete(); |
There was a problem hiding this comment.
(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.
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: