-
Notifications
You must be signed in to change notification settings - Fork 563
Fix: Ensure HttpContent stream rewinds on exception to support retry scenarios #10571
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
base: main
Are you sure you want to change the base?
Conversation
…arios Co-authored-by: jonathanpeppers <[email protected]>
Co-authored-by: jonathanpeppers <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@copilot the new test fails with: |
|
@copilot can you try again? |
|
@copilot try again. |
Co-authored-by: jonathanpeppers <[email protected]>
Fixed the test to catch all exception types instead of filtering specific ones. The test was failing because exceptions were being wrapped (AggregateException -> WebException -> SocketException) and not matching the catch filter. The test now:
This should resolve the test failure while still validating that the stream is properly rewound after exceptions. Commit: 5e3c725 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot I had several comments to clean up the new test.
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs
Outdated
Show resolved
Hide resolved
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs
Show resolved
Hide resolved
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs
Show resolved
Hide resolved
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs
Outdated
Show resolved
Hide resolved
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs
Outdated
Show resolved
Hide resolved
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs
Outdated
Show resolved
Hide resolved
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: jonathanpeppers <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot there is a build error:
(CoreCompile target) ->
/Users/runner/work/1/s/tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidMessageHandlerTests.cs(419,2): error CS1513: } expected [/Users/runner/work/1/s/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj]
the line number may not match exactly (as it didn't include your latest commit), but fix it please.
Co-authored-by: jonathanpeppers <[email protected]>
| [Test] | ||
| public async Task HttpContentStreamIsRewoundAfterCancellation () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@grendello what do you think? I think the fix is reasonable. Where the AI might be fooling us, it's questionable if the test actually tests what was fixed -- or if it is just random noise / AI hallucination. |

Plan to Fix Stream Rewind Issue in AndroidMessageHandler
WriteRequestContentToOutputdoesn't rewind the stream if an exception occurs duringCopyToAsyncSummary
This PR fixes a critical issue where
AndroidMessageHandlerdoes not rewind theHttpContentstream position if an exception occurs during upload. This preventedHttpContentfrom being safely reused in retry scenarios, leading to corrupted uploads or invalid requests.Changes Made
1. AndroidMessageHandler.cs
Wrapped
stream.CopyToAsync()in a try-finally block to ensure the stream is always rewound to position 0, even when an exception occurs during:This matches the behavior of iOS/macOS NSUrlSessionHandler and enables safe retry scenarios.
2. AndroidMessageHandlerTests.cs
Added comprehensive test
HttpContentStreamIsRewoundAfterCancellationthat validates:Test Improvements:
Exception.ToString()logging in all catch blocks for better diagnosticsThe test simulates real-world scenarios with cancellation tokens and large uploads (1 MB).
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.