Handle exceptions when resetting streams after writing to the network #1696
+13
−1
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.
We added the
isOneShot()
check to ensure that rewindable request body streams are reset after writing them e.g. to a logging interceptor. Previously, a logging interceptor would drain the request body stream causing the network call to have an empty body.However, we didn't handle the failure scenarios of
reset()
according to the docsThis PR makes a best effort measure to prevent draining the request body by an interceptor before the final network request.
If a positive content length is available, we
mark()
the start of the stream with the content length as the read limit.If during the
sink.writeAll()
a newmark()
is set causing thereset()
to fail, we log the exception.We do not fail the entire request in case the first call to
reset()
happens during the network call.closes microsoftgraph/msgraph-sdk-java#2245
(Pending end to end & unit tests)