Skip to content

[Wasm][Threading] garray.c:226: assertion 'array != NULL' failed #70572

@jeromelaban

Description

@jeromelaban

Description

After a while, when using threads, the runtime fails with multiple internal errors.

Reproduction Steps

Given a Wasm Threads enabled runtime, and the following code:

static void Main()
{
    Console.WriteLine($"Runtime Version: " + RuntimeInformation.FrameworkDescription);
    Console.WriteLine($"Runtime Mode: " + runtimeMode);
    Console.WriteLine($"TID: {Thread.CurrentThread.ManagedThreadId}");

    Bug01();
}

private static void Bug01()
{
    Timer t = new Timer(_ =>
    {
        Log($"Before GC");
        GC.Collect();
        Log($"After GC");
    });
    t.Change(5000, 0);

    Log($"-> Bug01");
    Task.Run(async () =>
    {
        var sw = Stopwatch.StartNew();
        Log($"Before 2000ms delay");
        await Task.Delay(2000);
        Log($"After delay {sw.ElapsedMilliseconds}");
    });
    Log($"<- Bug01");

    void Log(string message) => Console.WriteLine($"[TID:{Thread.CurrentThread.ManagedThreadId}] {message}");
}

Expected behavior

The runtime does not fail.

Actual behavior

After about 30 second, the following errors appear:

Runtime Version: .NET 7.0.0-dev
dotnet.js:12 Runtime Mode: InterpreterAndAOT
dotnet.js:12 TID: 1
dotnet.js:12 [TID:1] -> Bug01
dotnet.js:12 [TID:1] <- Bug01
dotnet.js:12 [TID:2] Before 2000ms delay
dotnet.js:12 
        
       Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread
warnOnce @ dotnet.js:12
dotnet.js:12 [TID:2] Before GC
dotnet.js:12 [TID:1] After delay 4991
dotnet.js:12 [TID:2] After GC
dotnet.js:3 
        
       Error: [MONO] D:/a/Uno.DotnetRuntime.WebAssembly/Uno.DotnetRuntime.WebAssembly/runtime/src/mono/mono/eglib/garray.c:226: assertion 'array != NULL' failed

    at mono_wasm_stringify_as_error_with_stack (dotnet.js:3:23680)
    at Object.mono_wasm_trace_logger (dotnet.js:3:24051)
    at _mono_wasm_trace_logger (dotnet.js:12:141805)
    at dotnet.wasm:0xb6d2
    at dotnet.wasm:0xaf509
    at dotnet.wasm:0x1cd5e6
    at dotnet.wasm:0x1cd617
    at dotnet.wasm:0xb6130
    at dotnet.wasm:0xb6474
    at dotnet.wasm:0xb6434
mono_wasm_trace_logger @ dotnet.js:3
_mono_wasm_trace_logger @ dotnet.js:12
$func128 @ dotnet.wasm:0xb6d2
$func2709 @ dotnet.wasm:0xaf509
$func8655 @ dotnet.wasm:0x1cd5e6
$func8656 @ dotnet.wasm:0x1cd617
$func2888 @ dotnet.wasm:0xb6130
$func2895 @ dotnet.wasm:0xb6474
$func2894 @ dotnet.wasm:0xb6434
$mono_set_timeout_exec @ dotnet.wasm:0x1c83e9
Module._mono_set_timeout_exec @ dotnet.js:12
o.<computed> @ dotnet.js:3
mono_wasm_set_timeout_exec @ dotnet.js:3
dotnet.js:12 
        
       worker sent an error! http://localhost:54601/package_9b1dc0ec76d5eb2e01aeed5412986838a4474a96/dotnet.wasm:1: Uncaught RuntimeError: memory access out of bounds
worker.onerror @ dotnet.js:12
dotnet.js:12 
        
       Uncaught ErrorEvent {isTrusted: true, message: 'Uncaught RuntimeError: memory access out of bounds', filename: 'http://localhost:54601/package_9b1dc0ec76d5eb2e01aeed5412986838a4474a96/dotnet.wasm', lineno: 1, colno: 62121, …}
worker.onerror @ dotnet.js:12
dotnet.wasm:0xf2a8 
        
       Uncaught RuntimeError: memory access out of bounds
    at dotnet.wasm:0xf2a8
    at dotnet.wasm:0x1ad6e0
    at dotnet.wasm:0x8dbcb
    at dotnet.wasm:0x8e30d
    at dotnet.wasm:0x1c846b
    at Module._mono_set_timeout_exec (dotnet.js:12:175165)
    at Object.o.<computed> (dotnet.js:3:5345)
    at mono_wasm_set_timeout_exec (dotnet.js:3:86487)

Regression?

no

Known Workarounds

None

Configuration

be4d292

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions