Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed a bug where retrying requests with bodies created from a mark/reset-capable `InputStream` could fail because the stream was closed between retry attempts. ([#49650](https://github.com/Azure/azure-sdk-for-java/pull/49650))

### Other Changes

## 1.58.1 (2026-06-08)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public int available() throws IOException {

@Override
public void close() throws IOException {
inner.close();
// No-op. The user/caller is responsible for closing the underlying stream's lifecycle,
// in line with the BinaryData.fromStream contract. Closing it here breaks stream replayability on retries.
}
Comment thread
arnabnandy7 marked this conversation as resolved.
Comment thread
arnabnandy7 marked this conversation as resolved.
Outdated
Comment thread
arnabnandy7 marked this conversation as resolved.
Outdated
Comment thread
arnabnandy7 marked this conversation as resolved.

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ public void expectedBodyLengthSync() throws IOException {
}
}

@Test
public void lengthValidatingInputStreamCloseDoesNotCloseUnderlying() throws IOException {
final boolean[] closed = new boolean[1];

try (InputStream innerStream = new ByteArrayInputStream(EXPECTED) {
@Override
public void close() throws IOException {
closed[0] = true;
super.close();
}
}) {
LengthValidatingInputStream validatingStream
= new LengthValidatingInputStream(innerStream, EXPECTED.length);

validatingStream.close();

// Validate that closing the wrapper does not close the underlying stream.
org.junit.jupiter.api.Assertions.assertFalse(closed[0],
"LengthValidatingInputStream.close() must not close the underlying stream.");
Comment thread
arnabnandy7 marked this conversation as resolved.
Outdated
}
Comment thread
arnabnandy7 marked this conversation as resolved.
}
Comment thread
arnabnandy7 marked this conversation as resolved.
Comment thread
arnabnandy7 marked this conversation as resolved.

private static Mono<byte[]> validateAndCollectRequestAsync(HttpRequest request) {
return RestProxyUtils.validateLengthAsync(request)
.flatMap(r -> FluxUtil.collectBytesInByteBufferStream(r.getBody()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ public void parallelParsing() throws InterruptedException {
return UrlBuilder.parse("https://example" + i + ".com");
}).collect(Collectors.toCollection(() -> new ArrayList<>(20000)));

List<Future<UrlBuilder>> futures = SharedExecutorService.getInstance().invokeAll(tasks, 10, TimeUnit.SECONDS);
List<Future<UrlBuilder>> futures = SharedExecutorService.getInstance().invokeAll(tasks, 60, TimeUnit.SECONDS);
Comment thread
arnabnandy7 marked this conversation as resolved.
Outdated
Comment thread
arnabnandy7 marked this conversation as resolved.
Outdated
for (Future<UrlBuilder> future : futures) {
assertTrue(future.isDone());
assertDoesNotThrow(() -> future.get());
Comment thread
arnabnandy7 marked this conversation as resolved.
Expand All @@ -726,7 +726,7 @@ public void fluxParallelParsing() {
return UrlBuilder.parse("https://example" + i + ".com");
})
.then()
.timeout(Duration.ofSeconds(10));
.timeout(Duration.ofSeconds(60));
Comment thread
arnabnandy7 marked this conversation as resolved.
Outdated
Comment thread
arnabnandy7 marked this conversation as resolved.
Outdated

StepVerifier.create(mono).verifyComplete();
assertEquals(20000, callCount.get());
Expand Down