-
Notifications
You must be signed in to change notification settings - Fork 5k
dotnet.js fails to initialize when running in a web worker with onmessage handler #114918
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
Comments
Tagging subscribers to 'arch-wasm': @lewing |
@bcairns-google I think you can do I did it here #92280 Does that work for you ? |
Setting Is there a particular reason to not resolve the promises in
ENVIRONMENT_IS_WORKER is true ? You said something earlier about multi-threading, I'm just trying to understand why this would interact with the loading behavior.
|
When dotnet starts in multi-threading mode it also has to load some of it's assets (think JS files). Those which are loaded into linear memory, are already loaded by main thread only. runtime/src/mono/browser/runtime/startup.ts Line 330 in cc2406f
which arrives by
|
I'm running into the same issue, and self.dotnetSidecar=true doesn't seem to fix the issue for me: const { getAssemblyExports, getConfig } = await dotnet
.withDiagnosticTracing(false)
.create(); still hangs. |
Description
When dotnet.js is started in a web worker with an onmessage handler, the promises for asset instantiation are never resolved and therefore initialization hangs.
There appears to be a check in browser/runtime/loader/assets.ts which checks for ENVIRONMENT_IS_WORKER and deliberately avoids resolving the promises:
runtime/src/mono/browser/runtime/loader/assets.ts
Line 244 in 7dcd892
and
runtime/src/mono/browser/runtime/loader/assets.ts
Line 253 in 7dcd892
If ENVIRONMENT_IS_WORKER is manually set to false in the debugger, loading will complete normally and dotnet.js functions correctly in a web worker.
ENVIRONMENT_IS_WORKER is set here:
runtime/src/mono/browser/runtime/loader/globals.ts
Line 30 in 28bbd27
The logic is a bit odd:
ENVIRONMENT_IS_WORKER is true if both of the following are true:
If globalThis.onmessage is undefined, globalThis.dotnetSidecar is set to true, ENVIRONMENT_IS_WORKER will be false, and loading works normally.
Reproduction Steps
Expected behavior
dotnet.js initializes successfully in the web worker.
Actual behavior
The dotnet.create() promise is never resolved and initialization hangs.
Regression?
This worked correctly in .NET 8.
This commit introduced the logic which breaks loading in a web worker with an onmessage handler:
8698d3d
Known Workarounds
Delete any globalThis.onmessage handler before calling dotnet.create()
Configuration
.NET SDK 9.0.203
Behavior can be reproduced in Chrome, Safari, Firefox, and presumably any other browser that Blazor supports.
Other information
No response
The text was updated successfully, but these errors were encountered: