Skip to content
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

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

Closed
jeromelaban opened this issue Jun 10, 2022 · 3 comments
Closed

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

jeromelaban opened this issue Jun 10, 2022 · 3 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-VM-threading-mono
Milestone

Comments

@jeromelaban
Copy link
Contributor

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

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 10, 2022
@lewing lewing added the arch-wasm WebAssembly architecture label Jun 10, 2022
@ghost
Copy link

ghost commented Jun 10, 2022

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

Issue Details

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

Author: jeromelaban
Assignees: -
Labels:

arch-wasm, untriaged

Milestone: -

@kg
Copy link
Contributor

kg commented Jun 23, 2022

Should be fixed by the combo of #70863 and #71229

@kg kg closed this as completed Jun 30, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-VM-threading-mono
Projects
None yet
Development

No branches or pull requests

3 participants