Skip to content

WebSocket exception with LLVM and full AOT Enabled in .NET Android App #104599

@kcrg

Description

@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:

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'">
  <EnableLLVM>True</EnableLLVM>
  <AndroidEnableProfiledAot>False</AndroidEnableProfiledAot>
  <RunAOTCompilation>True</RunAOTCompilation>
</PropertyGroup>

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:

Message: net_webstatus_ConnectFailure
StackTrace: at System.Net.WebSockets.WebSocketHandle.ConnectAsync(Uri , HttpMessageInvoker , CancellationToken , ClientWebSocketOptions )
   at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore(Uri , HttpMessageInvoker , CancellationToken )
   at WebsocketLLVMIssue.WebSocketClient.ConnectAsync(String uri)
   at WebsocketLLVMIssue.MainActivity.ConnectAsync()

Additional Notes:

  • Disabling LLVM resolves the issue, indicating a potential conflict between WebSocket operations and LLVM optimizations.
  • A repro project is attached to this issue for further investigation.

Steps to Reproduce

  1. Create a new .NET Android project.
  2. Implement WebSocket client functionality.
  3. Add UI elements for connecting, sending messages, and disconnecting.
  4. Handle user interactions to manage WebSocket operations.
  5. Configure the project to use LLVM without AOT.
  6. Build and run the project on an Android device or emulator.
  7. Observe the behavior when trying to connect using WebSocket.

Or download this minimal project: WebsocketLLVMIssue.zip

Did you find any workaround?

nope

Relevant log output

logcat.txt

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions