Skip to content

[CoreCLR] fibers on Windows - Wasmtime Async Compatibility #96293

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

Open
martindevans opened this issue Dec 24, 2023 · 10 comments
Open

[CoreCLR] fibers on Windows - Wasmtime Async Compatibility #96293

martindevans opened this issue Dec 24, 2023 · 10 comments
Labels
area-VM-coreclr os-windows untriaged New issue has not been triaged by the area owner

Comments

@martindevans
Copy link

martindevans commented Dec 24, 2023

Description

When C# is acting as the host for WASM execution (using wasmtime-dotnet), wasmtime will try to use fibers and fail.

Wasmtime supports async WASM execution, which can suspend running WASM code and resume it later.

Unfortunately the implementation seems to be incompatible with running inside dotnet.

Reproduction Steps

  1. Clone this PR which I wrote for wasmtime-dotnet to add async support
  2. Place a breakpoint inside an async callback
  3. Run tests
  4. Observe failures

Expected behavior

Wasmtime async should work in dotnet.

Whether this should involve a change to dotnet or a change to wasmtime I'm not sure. My motivation here is really just like to draw attention to this incompatibility and to get some input from dotnet developers on the PR.

Actual behavior

Tests fail with System.Runtime.InteropServices.SEHException when hitting a breakpoint.

According to this comment it can sometimes crash with "Fatal error. Internal CLR error." or "AccessViolationException".

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@ghost ghost added needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners untriaged New issue has not been triaged by the area owner labels Dec 24, 2023
@vcsjones vcsjones added arch-wasm WebAssembly architecture area-VM-meta-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Dec 24, 2023
@ghost
Copy link

ghost commented Dec 24, 2023

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Wasmtime supports async WASM execution, which can suspend running WASM code and resume it later.

Unfortunately the implementation seems to be incompatible with dotnet.

Reproduction Steps

  1. Clone this PR which I wrote for wasmtime-dotnet to add async support
  2. Place a breakpoint inside an async callback
  3. Run tests
  4. Observe failures

Expected behavior

Wasmtime async should work in dotnet.

Whether this should involve a change to dotnet or a change to wasmtime I'm not sure. My motivation here is really just like to draw attention to this incompatibility and to get some input from dotnet developers on the PR.

Actual behavior

Tests fail with System.Runtime.InteropServices.SEHException when hitting a breakpoint.

According to this comment it can sometimes crash with "Fatal error. Internal CLR error." or "AccessViolationException".

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: martindevans
Assignees: -
Labels:

arch-wasm, untriaged, area-VM-meta-mono

Milestone: -

@martindevans
Copy link
Author

I would guess arch-wasm probably isn't the right tag, since this is about using wasm within dotnet rather than dotnet within wasm.

@vcsjones
Copy link
Member

I would guess arch-wasm probably isn't the right tag

Yeah, I noticed - but it's probably the best way to get eyes on the issue from the right folks at this point in time - they can re-assign the arch if they feel it is incorrectly assigned.

@pavelsavara pavelsavara added the os-wasi Related to WASI variant of arch-wasm label Jan 23, 2024
@lewing lewing added this to the 9.0.0 milestone Apr 1, 2024
@lewing lewing removed the untriaged New issue has not been triaged by the area owner label Apr 1, 2024
@lewing lewing modified the milestones: 9.0.0, Future Apr 1, 2024
@lewing
Copy link
Member

lewing commented Apr 4, 2024

More work is happening here https://github.com/dicej/isyswasfa

@lewing lewing assigned pavelsavara and unassigned maraf Oct 13, 2024
@lewing lewing modified the milestones: Future, 10.0.0 Oct 13, 2024
@pavelsavara
Copy link
Member

I believe that we have initial implementation for this now for WASIp2.

See
https://github.com/dotnet/runtime/blob/main/src/mono/sample/wasi/http-p2/Program.cs

This will improve with WASIp3

@martindevans
Copy link
Author

@pavelsavara I don't think that resolves this issue. That looks like it's for async support when compiling C# to WASM. But this issue about the other case - when C# is acting as the host for WASM execution (using wasmtime-dotnet).

In this case the async features of wasmtime cannot be used because they are built with fibers, which are incompatible with dotnet:

The .NET threading model does not support fibers. You should not call into any unmanaged function that is implemented by using fibers. Such calls may result in a crash of the .NET runtime.
source.

@pavelsavara
Copy link
Member

pavelsavara commented Nov 7, 2024

Ah, so this is not about WASI at all. This is about CoreCLR vs wasmtime on windows

@pavelsavara pavelsavara reopened this Nov 7, 2024
@pavelsavara pavelsavara added os-windows and removed os-wasi Related to WASI variant of arch-wasm labels Nov 7, 2024
@pavelsavara
Copy link
Member

I think that somebody from CoreCLR needs to close this as won't fix.

@pavelsavara pavelsavara changed the title Wasmtime Async Compatibility [CoreCLR] fibers on Windows - Wasmtime Async Compatibility Nov 7, 2024
@pavelsavara pavelsavara removed their assignment Nov 7, 2024
@pavelsavara pavelsavara removed the arch-wasm WebAssembly architecture label Nov 7, 2024
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@pavelsavara pavelsavara removed this from the 10.0.0 milestone Nov 7, 2024
@martindevans
Copy link
Author

According to this comment from one of the Wasmtime developers there's no alternative way to implement stack switching on Windows others than fibers. If there's no chance of dotnet gaining support for using fibers is there some other dotnet compatible alternative wasmtime could switch to?

@pavelsavara pavelsavara added the untriaged New issue has not been triaged by the area owner label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-VM-coreclr os-windows untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

5 participants