Commit 3b0fa7b
Fix smart retry offset calculation to exclude pending buffer bytes
The root cause of "Unexpected segment number" errors was incorrect retry offset calculation. The pending buffer contains bytes that have already been counted in totalEncodedBytesProcessed but haven't been successfully processed by the decoder yet. When retrying, we were requesting bytes AFTER the pending buffer, causing gaps in the data stream.
Key issue:
- totalEncodedBytesProcessed tracks ALL bytes received (including those in pending)
- Pending buffer holds bytes waiting for more data to complete a structure (header/segment/footer)
- Retry offset was set to totalEncodedBytesProcessed, skipping pending bytes
- This caused decoder to receive segment N when expecting segment N-1
Solution:
1. Added getRetryOffset() method to DecoderState that returns: totalEncodedBytesProcessed - pendingBufferSize
2. Updated BlobAsyncClientBase to use getRetryOffset() instead of getTotalEncodedBytesProcessed()
3. Added import for DecoderState inner class
Example flow:
- Receive bytes 0-4, add to totalEncodedBytesProcessed (=5), insufficient for 13-byte header, store in pending
- IOException occurs
- Retry requests from offset 0 (5 - 5 pending bytes = 0) ✓
- Get byte 5, combine with pending [0-4] = [0-5], still insufficient, store in pending
- totalEncodedBytesProcessed now = 6, pending = 6 bytes
- Retry requests from offset 0 (6 - 6 = 0) ✓
- Continue until enough bytes accumulated
This ensures continuous byte stream to decoder with no gaps or duplicates.
Co-authored-by: gunjansingh-msft <[email protected]>1 parent 899bfb4 commit 3b0fa7b
File tree
2 files changed
+18
-4
lines changed- sdk/storage
- azure-storage-blob/src/main/java/com/azure/storage/blob/specialized
- azure-storage-common/src/main/java/com/azure/storage/common/policy
2 files changed
+18
-4
lines changedLines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
1404 | 1405 | | |
1405 | 1406 | | |
1406 | 1407 | | |
1407 | | - | |
1408 | | - | |
| 1408 | + | |
1409 | 1409 | | |
1410 | | - | |
1411 | | - | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
1412 | 1413 | | |
1413 | 1414 | | |
1414 | 1415 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
285 | 298 | | |
286 | 299 | | |
287 | 300 | | |
| |||
0 commit comments