Commit ec7de83
Fix smart retry by preserving partial data in pending buffer on decoder exceptions
The root cause of "Unexpected segment number" errors was that when the decoder threw exceptions due to insufficient data (e.g., "Content not long enough"), the partial data was not saved to the pending buffer. This caused retries to lose accumulated bytes and start over.
Key changes:
1. Moved buffer combination and byte tracking outside try block to execute regardless of decoder success/failure
2. Added specific handling for IllegalArgumentException with "not long enough" message
3. When insufficient data error occurs, save all accumulated data to pending buffer and return empty (don't fail)
4. This allows the stream to continue accumulating bytes across retries until enough data is available for decoding
How it works now:
- Request bytes=0-: Get byte 0, insufficient for header, save to pending, return empty
- Stream error triggers retry
- Request bytes=1-: Get byte 1, combine with pending [byte 0], still insufficient, save [0,1] to pending
- Continue until 13+ bytes accumulated in pending
- Eventually enough bytes available, decoder succeeds and processes the header
- Smart retry resumes from correct encoded offset
This fix enables true smart retry where partial data is preserved across network interruptions.
Co-authored-by: gunjansingh-msft <[email protected]>1 parent d3d9700 commit ec7de83
File tree
1 file changed
+19
-6
lines changed- sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy
1 file changed
+19
-6
lines changedLines changed: 19 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
90 | | - | |
| 88 | + | |
| 89 | + | |
91 | 90 | | |
92 | | - | |
93 | | - | |
94 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
95 | 94 | | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
117 | 130 | | |
118 | 131 | | |
119 | 132 | | |
| |||
0 commit comments