Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exceptions when resetting streams after writing to the network #1696

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Ndiritu
Copy link
Contributor

@Ndiritu Ndiritu commented Dec 9, 2024

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 docs

This 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 new mark() is set causing the reset() 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)

@Ndiritu Ndiritu self-assigned this Dec 9, 2024
@Ndiritu Ndiritu force-pushed the fix/request-body-stream-reset branch from ab60655 to 2bf7173 Compare December 9, 2024 20:42
Copy link

sonarcloud bot commented Dec 9, 2024

@ihudedi
Copy link

ihudedi commented Dec 11, 2024

Hi @Ndiritu
I saw another call to reset in this file and exception is thrown

Thanks,
Itay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Upload file to Sharepoint failed with 'Stream mark expired' when the inputstream is markSuppoted
2 participants