Map cancelled request body uploads to OperationCanceledException in AndroidMessageHandler#11683
Draft
Copilot wants to merge 3 commits into
Draft
Map cancelled request body uploads to OperationCanceledException in AndroidMessageHandler#11683Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
…Exception Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix cancelled PUT request mapping to IOException
Map cancelled request body uploads to OperationCanceledException in AndroidMessageHandler
Jun 17, 2026
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.
When a caller cancels the
CancellationTokenwhileAndroidMessageHandleris still uploading a request body (e.g. aPUTwhose body the server delays reading), the cancellation surfaced asWebException/IOException("Socket closed") instead of anOperationCanceledExceptionsubtype, diverging fromSocketsHttpHandler.The cancellation callback disconnects the socket, so the in-flight
CopyToAsynctohttpConnection.OutputStreamthrowsJava.IO.IOException, which was then wrapped into aWebExceptionbyDoSendAsync. The response-body read path already mapped these to cancellation; the request-upload path did not.Changes
WriteRequestContentToOutput: catch transport exceptions thrown during the body copy when cancellation has been requested, and rethrow asSystem.OperationCanceledExceptiontied to the caller's token.ShouldMapToCancellation: hoisted from the nestedCancellationAwareResponseStreamto the enclosingAndroidMessageHandlerso the upload and response-read paths share one mapping rule (no change to the existing response-read behavior).RequestBodyUploadCancellationIsPromptstalls a raw-socket server after reading the request headers, streams a large body in chunks until the send buffer blocks, cancels mid-upload, and asserts a promptOperationCanceledException.