Skip to content

Commit 12fe68d

Browse files
Fix byte tracking to count received bytes not consumed bytes
The issue was that totalEncodedBytesProcessed was tracking consumed bytes (what the decoder processed), but it should track received bytes (what came from the network). This ensures retry requests fetch new data after what was already received, while the pending buffer holds unconsumed bytes. On retry: request starts after all received bytes, decoder continues from its internal state with pending bytes, new bytes appended after pending. Co-authored-by: gunjansingh-msft <[email protected]>
1 parent 9d78ce1 commit 12fe68d

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/StorageContentValidationDecoderPolicy.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
8585
*/
8686
private Flux<ByteBuffer> decodeStream(Flux<ByteBuffer> encodedFlux, DecoderState state) {
8787
return encodedFlux.concatMap(encodedBuffer -> {
88-
// Track how many bytes were pending before we process
89-
int previousPendingBytes = (state.pendingBuffer != null) ? state.pendingBuffer.remaining() : 0;
88+
// Track the NEW bytes received from the network (before combining with pending)
89+
int newBytesReceived = encodedBuffer.remaining();
90+
state.totalEncodedBytesProcessed.addAndGet(newBytesReceived);
9091

9192
// Combine with pending data if any
9293
ByteBuffer dataToProcess = state.combineWithPending(encodedBuffer);
@@ -105,14 +106,6 @@ private Flux<ByteBuffer> decodeStream(Flux<ByteBuffer> encodedFlux, DecoderState
105106
int bytesConsumed = duplicateForDecode.position() - initialPosition;
106107
int bytesRemaining = availableSize - bytesConsumed;
107108

108-
// Track the newly consumed encoded bytes (excluding previously pending bytes)
109-
// The consumed bytes include both old pending bytes and new bytes from this buffer
110-
// We only want to add the NEW bytes that were consumed
111-
int newBytesConsumed = bytesConsumed - previousPendingBytes;
112-
if (newBytesConsumed > 0) {
113-
state.totalEncodedBytesProcessed.addAndGet(newBytesConsumed);
114-
}
115-
116109
// Save only unconsumed portion to pending
117110
if (bytesRemaining > 0) {
118111
// Position the original buffer to skip consumed bytes, then slice to get unconsumed

0 commit comments

Comments
 (0)