[go: up one dir, main page]

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] Task.Delay only continues after a GC #70571

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

[Wasm][Threading] Task.Delay only continues after a GC #70571

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
jeromelaban commented Jun 10, 2022

Description

Given a Wasm Threads enabled runtime, using Task.Delay waits for the next GC to continue.

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}");
}

Shows the following

Expected behavior

The Async method continues after about 2 seconds, not when the GC has been invoked.

Actual behavior

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
dotnet.js:12 [TID:2] Before GC
dotnet.js:12 [TID:1] After delay 5690
dotnet.js:12 [TID:2] After GC

Regression?

no

Known Workarounds

none

Configuration

be4d292

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 10, 2022
@ghost
Copy link
ghost commented Jun 10, 2022

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

Issue Details

Description

Given a Wasm Threads enabled runtime, using Task.Delay waits for the next GC to continue.

Reproduction Steps

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

static void Main()
{
    var runtimeMode = Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_MONO_RUNTIME_MODE");
    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}");
}

Shows the following

Expected behavior

The Async method continues after about 2 seconds, not when the GC has been invoked.

Actual behavior

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
dotnet.js:12 [TID:2] Before GC
dotnet.js:12 [TID:1] After delay 5690
dotnet.js:12 [TID:2] After GC

Regression?

no

Known Workarounds

none

Configuration

be4d292

Other information

No response

Author: jeromelaban
Assignees: -
Labels:

area-System.Threading

Milestone: -

@lewing lewing added this to the 7.0.0 milestone Jun 10, 2022
@lewing lewing added arch-wasm WebAssembly architecture and removed untriaged New issue has not been triaged by the area owner labels 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

Given a Wasm Threads enabled runtime, using Task.Delay waits for the next GC to continue.

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}");
}

Shows the following

Expected behavior

The Async method continues after about 2 seconds, not when the GC has been invoked.

Actual behavior

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
dotnet.js:12 [TID:2] Before GC
dotnet.js:12 [TID:1] After delay 5690
dotnet.js:12 [TID:2] After GC

Regression?

no

Known Workarounds

none

Configuration

be4d292

Other information

No response

Author: jeromelaban
Assignees: -
Labels:

arch-wasm, area-System.Threading

Milestone: 7.0.0

@kg
Copy link
Member
kg commented Jun 23, 2022

Fixed by #70863

@kg kg closed this as completed Jun 23, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 24, 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