Skip to content

Commit 107ee8c

Browse files
Fix retry offset calculation - use totalEncodedBytesProcessed to request new bytes
The root cause was using getRetryOffset() (which subtracts pending bytes) to determine what to request from the server. This caused requesting bytes we already have in the pending buffer, creating duplicates. The correct logic: - totalEncodedBytesProcessed tracks ALL bytes we've received from the server (including those in pending) - pending buffer holds bytes waiting for more data to complete a structure - When retrying, we need to request NEW bytes starting from totalEncodedBytesProcessed - The pending buffer will be combined with new bytes in the policy's decodeStream method Example: 1. Request bytes=0-, get byte 0, totalEncodedBytesProcessed=1, pending=[0] 2. IOException, retry requesting bytes=1- (starting from totalEncodedBytesProcessed=1) 3. Get byte 1, combine with pending [0] + [1] = [0,1], totalEncodedBytesProcessed=2 4. Still insufficient, pending=[0,1], continue... This ensures: - No duplicate bytes from server - Pending buffer accumulates across retries - Decoder receives continuous byte stream - Smart retry resumes from correct offset Addresses comment #2499104452. Co-authored-by: gunjansingh-msft <[email protected]>
1 parent 3b0fa7b commit 107ee8c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/specialized/BlobAsyncClientBase.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,9 +1407,10 @@ Mono<BlobDownloadAsyncResponse> downloadStreamWithResponse(BlobRange range, Down
14071407
if (decoderStateObj instanceof StorageContentValidationDecoderPolicy.DecoderState) {
14081408
DecoderState decoderState = (DecoderState) decoderStateObj;
14091409

1410-
// Use the retry offset (encoded bytes processed minus pending buffer)
1411-
// The pending buffer contains bytes that have been counted but not yet successfully processed
1412-
long encodedOffset = decoderState.getRetryOffset();
1410+
// Use totalEncodedBytesProcessed to request NEW bytes from the server
1411+
// The pending buffer already contains bytes we've received, so we request
1412+
// starting from the next byte after what we've already received
1413+
long encodedOffset = decoderState.getTotalEncodedBytesProcessed();
14131414
long remainingCount = finalCount - encodedOffset;
14141415
retryRange = new BlobRange(initialOffset + encodedOffset, remainingCount);
14151416

0 commit comments

Comments
 (0)