fix: InputStreamContent closes caller InputStream between retry attempts#49650
Open
arnabnandy7 wants to merge 13 commits into
Open
fix: InputStreamContent closes caller InputStream between retry attempts#49650arnabnandy7 wants to merge 13 commits into
arnabnandy7 wants to merge 13 commits into
Conversation
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
Contributor
|
Thank you for your contribution @arnabnandy7! We will review the pull request and get back to you soon. |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an InputStreamContent retry regression in azure-core where request-body length validation wrapped the caller’s InputStream in LengthValidatingInputStream, and the wrapper’s close() would close the underlying caller stream between retry attempts—breaking mark/reset replayability and causing subsequent retries to fail with IOException: Stream closed.
Changes:
- Changed
LengthValidatingInputStream.close()to be a no-op to avoid closing the underlying user-providedInputStreambetween retries. - Added in-code rationale tying the behavior to the
BinaryData.fromStreamownership/closure contract.
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
Apply Spotless formatting to the strengthened close/reset regression test and remove an accidental duplicate semicolon.
Document caller-owned stream handling in LengthValidatingInputStream, use assertFalse in the close/reset regression test, and revert unrelated UrlBuilder timeout increases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request resolves Issue #49648, where
InputStreamContentbuilt from a mark/reset-capableInputStreamloses replayability after a failed HTTP attempt, causing all subsequent retries to fail with anIOException: Stream closedexception.Root Cause
When validating the body length of a request,
RestProxyUtilswraps theInputStreamin aLengthValidatingInputStream. Upon a failed request, the HTTP client/reactive pipeline cleans up resources by callingclose()on the wrapped stream.LengthValidatingInputStream.close()was unconditionally delegating theclose()call to the underlying user-provided stream, thereby closing it prematurely. On subsequent retries, when the pipeline callsreset()on the wrapped stream, the underlying stream throws a "Stream closed" exception as it has already been closed.Fix
Updated
LengthValidatingInputStream.close()to be a no-op. Since the contract ofBinaryData.fromStream(inputStream)guarantees that the Azure SDK does not take ownership or close the user-provided stream (the caller is responsible for its lifecycle), the REST proxy should not close the underlying stream either.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines