Search code examples
c#.net-coremonowasiwasmtime

Why does .NET Wasi.Sdk throw on garbage collection?


When using the .NET WASI SDK it seems the garbage collector throws, either when it runs itself in the background or when called explicitly.

I lodged an issue on Github but Microsoft are not responding (there's another similar issue on there for over a year).

My question here is, is there some setup issue on my part? All I've done is install latest wasmtime, created a .NET 8 console application, added the latest dotnet-wasi-sdk nuget package and try to run the below program and error happens.

Funnily enough, it's able to run other far more complex code but crashes when it does it's own garbage collection.

I suspect there is a setup/configuration issue on my part. Any ideas?

Error

[wasm_trace_logger] * Assertion at /home/runner/work/dotnet-wasi-sdk/dotnet-wasi-sdk/modules/runtime/src/mono/mono/metadata/sgen-stw.c:77, condition `info->client_info.stack_start >= info->client_info.info.stack_start_limit && info->client_info.stack_start < info->client_info.info.stack_end' not met

Repo

https://github.com/HermanSchoenfeld/WasiSdkBug

Offending Code

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args) {
            GC.Collect();
        }
    }
}

Environment

.NET 8, .NET 7
Wasi.Sdk 0.1.4-preview.10020 and 0.1.1
wasmtime-cli 19.0.2 (040ec9209 2024-04-11)

Solution

  • Issue was resolved by using the WASI SDK integration in .NET 8 and not that repo.

    It's all experimental but looks promising.