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

[browser][mt] Running any Thread for longer than 5000 ms crashes runtime (Blazor) #86903

Closed
IsaMorphic opened this issue May 30, 2023 · 15 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-VM-threading-mono needs-author-action An issue or pull request that requires more info or actions from the author. os-browser Browser variant of arch-wasm

Comments

@IsaMorphic
Copy link
Contributor

Description

Spawning any long-running Task or Thread from the main thread for longer than 5000 ms kills application and runtime when using Blazor.
Screenshot 2023-05-29 182353

Reproduction Steps

  1. Create empty Blazor app and use current main build of runtime in project file
  2. Use Task.Run, Thread.Start or async/await anywhere in the app with a long-running task (importantly, NOT Task.Yield or Task.Delay)
  3. Observe the error and runtime crash.

Expected behavior

I should be able to start a task from anywhere on the main thread using Task.Run in a Blazor app and not have the runtime crash after 5000ms

Actual behavior

Runtime crashes with error (screenshot above)

Regression?

This previously worked perfectly on the official release build of .NET 8 Preview 4.

Known Workarounds

None

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 30, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label May 30, 2023
@IsaMorphic
Copy link
Contributor Author

IsaMorphic commented May 30, 2023

Most likely this change is the cause of the issue: #86278

Edit:
After reverting the PR locally and trying the reproduction steps again, I have found that the error persists.

@vcsjones vcsjones added arch-wasm WebAssembly architecture area-VM-threading-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 30, 2023
@ghost
Copy link

ghost commented May 30, 2023

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

Issue Details

Description

Spawning any long-running Task or Thread from the main thread for longer than 5000 ms kills application and runtime when using Blazor.
Screenshot 2023-05-29 182353

Reproduction Steps

  1. Create empty Blazor app and use current main build of runtime in project file
  2. Use Task.Run, Thread.Start or async/await anywhere in the app with a long-running task (importantly, NOT Task.Yield or Task.Delay)
  3. Observe the error and runtime crash.

Expected behavior

I should be able to start a task from anywhere on the main thread using Task.Run in a Blazor app and not have the runtime crash after 5000ms

Actual behavior

Runtime crashes with error (screenshot above)

Regression?

This previously worked perfectly on the official release build of .NET 8 Preview 4.

Known Workarounds

None

Configuration

No response

Other information

No response

Author: IsaMorphic
Assignees: -
Labels:

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

Milestone: -

@lambdageek
Copy link
Member

@IsaMorphic Can you say a bit more about what's in the body of the long-running task? Is it compute-intensive? doing a synchronous call to JS that takes longer than 5 seconds? calling some native wasm code (like C code)?

In principle if the long-running task is just a compute loop in C# it should be trying to safepoint at backward branches in the loops... unless we're failing to emit the safepointing opcodes for some reason...

@IsaMorphic
Copy link
Contributor Author

@lambdageek Of course. It is definitely a compute intensive task in .NET land. No interop is happening inside of it.

@lewing lewing added this to the 8.0.0 milestone May 30, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label May 30, 2023
@lewing lewing modified the milestones: 8.0.0, 9.0.0 Jul 25, 2023
@pavelsavara pavelsavara added the os-browser Browser variant of arch-wasm label Nov 9, 2023
@pavelsavara pavelsavara assigned pavelsavara and unassigned maraf Nov 9, 2023
@pavelsavara
Copy link
Member

This is GC trying to suspend a thread. Probably UI thread is unbalanced on GC state.

@pavelsavara
Copy link
Member

Related #96190

@pavelsavara
Copy link
Member

@lambdageek is there way how to test safepoint with unit test ?

@lambdageek
Copy link
Member

@lambdageek is there way how to test safepoint with unit test ?

Start a GC

@pavelsavara
Copy link
Member

Create tight for loop and make sure it runs longer than MONO_SLEEP_ABORT_LIMIT.
And start GC on the other thread, right ?
Could we do better ?

@lambdageek
Copy link
Member

Well it's cooperative suspension, so we can add an icall that intentionally forgets to do a GC state transition and calls sleep. then call that on thread 1 and have thread 2 trigger a GC. I think that would behave a little better in the chrome debugger than doing a tight loop.

@IsaMorphic
Copy link
Contributor Author

Any updates on this investigation / fix? I'm eagerly awaiting the moment that this bug is squashed, as I am building an app that heavily relies on this functionality!

@pavelsavara
Copy link
Member

@IsaMorphic is it still possible to replicate with the latest build ?

You can try it with nightly build https://aka.ms/dotnet/9.0.1xx/daily/dotnet-sdk-win-x64.zip

@pavelsavara pavelsavara added the needs-author-action An issue or pull request that requires more info or actions from the author. label May 6, 2024
Copy link
Contributor

This issue has been marked needs-author-action and may be missing some important information.

Copy link
Contributor

This issue has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

Copy link
Contributor

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@dotnet-policy-service dotnet-policy-service bot removed this from the 9.0.0 milestone Jun 3, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 4, 2024
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 needs-author-action An issue or pull request that requires more info or actions from the author. os-browser Browser variant of arch-wasm
Projects
None yet
Development

No branches or pull requests

6 participants