Skip to content

[.NET 11] AndroidMessageHandler still throws IOException during upload #12934

Closed

Description

@tipa

Android framework version

net11.0-android (Preview)

Description

I hit System.IO.IOException: Software caused connection abort while uploading to OneDrive after moving my app to .NET 11. The inner exception is Java.Net.SocketException, and the stack points to AndroidMessageHandler.WriteRequestContentToOutput.

The attached repro triggers the same exception types by resetting a connection during a PUT upload. AndroidMessageHandler throws IOException; SocketsHttpHandler throws the expected HttpRequestException. The token is never cancelled.

This looks like a remaining case after #11682. The related fixes in #11683 and #11554 cover cancellation, which doesn't apply here.

The Preview 6 release notes say:

AndroidMessageHandler is brought in line with the HttpClient contract and SocketsHttpHandler behavior

Could this case also be fixed before .NET 11 ships? I simplified my error handling after the migration to catch HttpRequestException for network failures. This error now bypasses the retry and shows an unexpected-error dialog.

Steps to Reproduce

  1. Extract AndroidMessageHandlerUploadAbort-source.zip
  2. Build and run the app on a device or emulator using the commands in README.md.
  3. Read the results on screen or with adb logcat -s UploadAbortRepro:I.

The app runs its own loopback server, which reads the headers and 1 KiB of a 16 MiB upload, then resets the connection with SO_LINGER=0. No external server or account is needed.

Results

Reproduced on three consecutive launches on each device:

Handler Exception from SendAsync Inner exception
AndroidMessageHandler System.IO.IOException Java.Net.SocketException
SocketsHttpHandler System.Net.Http.HttpRequestException System.IO.IOException

The Android handler's stack includes WriteRequestContentToOutput. Both tokens remain uncancelled. I would expect HttpRequestException from both handlers for this network failure.

Environment

  • net11.0-android, SDK 11.0.100-rc.1.26425.128
  • Android workload 37.0.0-rc.1.2257
  • Physical Pixel 7: Android 17 / API 37, arm64
  • Pixel 9a emulator: Android 16 / API 36 (android-36.1 image), x86_64

Activity

  1. added
    Area: App Runtime
    needs-triage
    on Sep 27, 2026
  2. jonathanpeppers commented on Oct 12, 2026

    @jonathanpeppers
    Member

    @tipa can your app use UseNativeHttpHandler=false? To use the default .NET networking stack? (System.Net.Http.SocketsHttpHandler)

  3. tipa commented on Oct 13, 2026

    @tipa
    Author

    I tried UseNativeHttpHandler=false. In my tests, fresh Microsoft Graph requests were around 50–200 ms slower than with AndroidMessageHandler, especially on older Android devices. Results were mixed with reused connections.
    Tracing pointed to TLS, and offline tests suggested repeated trust-store setup in X509Chain.Build contributes to the cost. Is this a known tradeoff (alongside the mentioned app-size increase), and is there a recommended mitigation for periodic background sync checks ahead of the .NET 12 default switch?

  4. simonrozsival commented on Oct 13, 2026

    @simonrozsival
    Member

    Tracing pointed to TLS, and offline tests suggested repeated trust-store setup in X509Chain.Build contributes to the cost

    I'll look into this. We should make sure there isn't any perf regression before this becomes the default in .NET 12 (or we might roll this change back).

  5. simonrozsival commented on Oct 13, 2026

    @simonrozsival
    Member

    @tipa, a follow-up on the TLS performance investigation: I reproduced the slow certificate-chain construction on an Android device. On a Samsung device running Android 16, an offline X509Chain.Build of the supplied Microsoft Graph chain took about 170 ms. This was with revocation checking and certificate downloads disabled, so that time was not network I/O.

    The main contributor appears to be constructing Java's PKIXBuilderParameters from AndroidCAStore. That constructor enumerates and materializes the store's trust anchors for each chain; this step alone took about 123 ms with 143 anchors. Creating/loading the KeyStore was comparatively negligible, and reusing the same KeyStore did not avoid the enumeration. This is consistent with the extra cost on fresh TLS connections and the much smaller difference once connections are pooled.

    I have a local dotnet/runtime prototype that uses targeted lookup against the live trust store when a root is available, rather than enumerating every root. It still performs independent certificate-chain validation and falls back to the full store when necessary; it is not a permanent root cache or a replacement of managed validation with the platform trust manager. In the same offline workload, the prototype reduced the median chain-build time to about 8 ms. Validation and review are still in progress.

    I'm aiming to open a dotnet/runtime PR with the improvement this week, but it is still unclear whether it will land in time for .NET 11 GA. This performance work is separate from the upload exception fix, and these measurements do not establish that the slowdown was introduced in .NET 11.

    Note

    This update was drafted with GitHub Copilot.

  6. added a commit that references this issue on Oct 15, 2026
    d3edb44
  7. simonrozsival commented on Oct 21, 2026

    @simonrozsival
    Member

    The runtime perf fix has been merged into main (dotnet/runtime#135928) and it will be shipping with .NET 12. I don't think we will want to or be able to backport this change to .NET 11 (we already hit code complete).

  8. tipa commented on Oct 21, 2026

    @tipa
    Author

    Thanks for fixing this! Could the TLS performance fix be considered for a .NET 11 servicing release rather than waiting for .NET 12?
    Will the AndroidMessageHandler upload exception fix included in the .NET 11 GA workload?

  9. added a commit that references this issue on Oct 27, 2026
    af8beba
  10. locked and limited conversation to collaborators on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: App Runtimeneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions