Repository navigation
Description
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:
AndroidMessageHandleris brought in line with theHttpClientcontract andSocketsHttpHandlerbehavior
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
- Extract AndroidMessageHandlerUploadAbort-source.zip
- Build and run the app on a device or emulator using the commands in
README.md. - 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, SDK11.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.1image), x86_64
Activity
[Mono.Android] Default to SocketsHttpHandler in .NET 12 (#13013)
jonathanpeppers commentedon Oct 12, 2026
@tipa can your app use
UseNativeHttpHandler=false? To use the default .NET networking stack? (System.Net.Http.SocketsHttpHandler)tipa commentedon Oct 13, 2026
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?
simonrozsival commentedon Oct 13, 2026
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).
simonrozsival commentedon Oct 13, 2026
@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.Buildof 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
PKIXBuilderParametersfromAndroidCAStore. 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 theKeyStorewas comparatively negligible, and reusing the sameKeyStoredid 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.
Fix AndroidMessageHandler upload I/O exception translation (#13125) (#…
simonrozsival commentedon Oct 21, 2026
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).
tipa commentedon Oct 21, 2026
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?
Fix AndroidMessageHandler upload I/O exception translation (dotnet#13125