-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
WebSocket exception with LLVM and full AOT Enabled in .NET Android App #104599
Comments
@kcrg Could you please collect more info for us by issuing the following commands from the VS Developer Prompt: > adb shell setprop debug.mono.log default,assembly,mono_log_level=debug,mono_log_mask=all
> adb logcat -G 65M
> adb logcat -c
rem Start the crashing application here, wait for it to crash, then wait 5 more seconds and...
> adb logcat -d > logcat.txt Then attach the resulting |
@grendello Done, I just added the logcat.txt to the issue. Issue occures only in Release. Enabling AOT and LLVM in Debug mode seems wrong. |
Oops, my bad, sorry about that. The first command should be: > adb shell setprop debug.mono.log default,assembly,mono_log_level=debug,mono_log_mask=all And please attach |
@grendello Here it is: logcat.txt |
@kcrg it looks like a runtime issue, I can't find anything that's specific to .NET for Android. @steveisok I don't have permissions to transfer this to |
Tagging subscribers to this area: @dotnet/ncl |
Looking into the log, this seems network related:
@simonrozsival could you please take a quick look if this is something we've seen before or it's new... |
@vitek-karas @simonrozsival that exception is a red herring, it comes from a different (system) process. The one that is relevant is the following:
It is also related to networking, and the weird thing is that AOT+LLVM somehow makes the connection fail. |
Thanks a lot @grendello - learning :-) |
I can reproduce the issue locally, this is the exception stack trace I'm getting:
I get the same failure if I keep the same LLVM configuration, but I simply to connect a Socket: try
{
var socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
await socket.ConnectAsync(IPEndPoint.Parse("1.1.1.1:443"), CancellationToken.None);
}
catch (Exception ex)
{
Console.WriteLine(ex);
} I get the following exception:
This means that using @wfurt do you have an idea what could be going on? |
no, I don't know why AOT would make any difference. (assuming same code runs OK on Android without AOT) This seems to come from the
perhaps you can look at it in debugger and check the token version(s). cc @stephentoub for any more recommendations. |
Investigation updateThe failures does reproduce in
However, I was not able to reproduce the same issue on iOS (which uses AOT-llvm as well) or with a Mono sample app on arm64 desktop in AOT-llvm configuration. What's more, the Android sample app in dotnet/runtime also doesn't reproduce the issue (setting I'm thinking that there might be a conflict between dotnet/runtime and dotnet/android LLVMs which is causing some unexpected behavior. @jonathanpeppers do you know who would be the best person to discuss this issue with? |
@grendello or I might be able to help, depending what the problem is. Do you know if there is some AOT compiler flag/option we are missing that iOS has? Offhand, |
One thing that might be wrong is the newer LLVM linkers tend to rewrite code at link time and that breaks Mono's AOT since it expects to find the exact same code at run time as it generated at compile time. To prevent lld from doing this, we pass the |
I checked the binlogs and the
What I've noticed that is that on iOS, we use by default I'll try to get the disassembled source of @BrzVlad any thoughts on how to investigate this? |
We have the same issue using latest Azure.Storage.Blobs nuget for the azure file upload functions |
Experiencing the same issue - we noticed it a while ago (maybe 6mo or so), didn't have a chance to report. The exception we get is identical to this one: #104599 (comment) |
Just checked the sample from .zip on .NET 9 Preview 7: it works. That was the only modification (+ install whatever is required): <TargetFramework>net9.0-android</TargetFramework> |
@alexyakunin By changing only target framework to .NET 9, you disable the below PropertyGroup with Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'" If u want to test if it works on .NET 9, update Condition in this PropertyGroup to .NET 9. Here's how csproj looks like on .NET 9:
The issue still persists in .NET 9 rc1. |
@kcrg Oh, you're right - I forgot to change the framework identifier in Which means we also really need this fix. |
Also experiencing this issue when attempting to bring a Xamarin.Android app to .NET 8.0/9.0 while using regular TCP sockets. Same exception as described here: #104599 (comment) |
Hi guys, are there any updates on that? In particular, will the issue with WebSockets and sockets be addressed @ .NET 9 release? |
The issue was moved to .NET 10 so the fix likely won't be part of the .NET 9 release but will be backported to .NET 9 servicing when ready. We don't have any update yet as we are prioritizing .NET 9 issues before the release. In the meantime, could you try setting disabling LLVM to work around this issue ( |
It works in this case - both in our app and in the demo app above. |
Thank you for the update. Could you please share the reasons behind enabling LLVM on Android? I don't think it is enabled by default. |
|
@kcrg
|
@jonathanpeppers so what is the difference between This is confusing to me. Also
First thought was that it applies to Android 9, second thought was that I'm reading the .NET for Android release notes, so it applies to .NET 9 itself. I know there was a name change Xamarin.Android -> .NET for Android, I think a better option is to put the version number right after ".NET" -> .NET 9 for Android |
|
Okey, a quick update: you can workaround this issue by adding this piece to .csproj:
More sophisticated fix idea is to generate AOT build of System.Net.Sockets.dll w/o LLVM. I don't have time to work on it now, + I suspect it won't change much in terms of perf. So if someone else comes up w/ the modifications needed, please share. CC @kcrg |
Android framework version
net8.0-android, net9.0-android
Affected platform version
VS 17.11 Preview and 17.10 Stable, .NET 8.0.6 and .NET 9.0.0-preview.5.24306.8
Description
I am encountering an issue with WebSocket functionality in a .NET Android application when LLVM and full AOT is enabled. The application fails to establish WebSocket connections.
Configuration:
When running the application with the above configuration, WebSocket connections throws exception. The same code works without issues when LLVM is disabled.
Expected Behavior:
The WebSocket connection should be established, messages should be sent and received without errors, and the connection should be properly closed.
Actual Behavior:
WebSocket connection throws exception when LLVM is enabled with the above configuration.
Stack Trace:
Additional Notes:
Steps to Reproduce
Or download this minimal project: WebsocketLLVMIssue.zip
Did you find any workaround?
nope
Relevant log output
logcat.txt
The text was updated successfully, but these errors were encountered: