Skip to content

[browser][mt] Upgrade emscripten #75625

Closed

Description

@lambdageek

In a threaded .NET runtime, Emscripten prints this to the JS console even if C# user code doesn't do any threading

Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread

This comes from https://github.com/emscripten-core/emscripten/blob/678d7d8881a810d14f52bb3b7e72a8c337b571ba/src/library_pthread.js#L785

which gets called from various pthread primitives that the runtime calls, such as pthread_join or pthread_cond_timedwait.

We should try setting -s ALLOW_BLOCKING_ON_MAIN_THREAD=false and investigate whether the blocking operations are really necessary. If fixing the blocking is infeasible, we should consider overriding Module.PThread.emscripten_check_blocking_allowed to not nag.

Activity

  1. added this to the 8.0.0 milestone on Sep 14, 2022
  2. pavelsavara commented on Jun 20, 2023

    @pavelsavara
    Member

    image

    This is how mono thread pool joins threads in order to finalize them.

    Other significant use is mono_os_mutex_lock which is used in about 40 places

    • GC
    • threadpool
    • debugger
    • mini

    I think that we are unlikely to be able to remove it.
    Alternate strategy could be to run mono always on the worker.

  3. modified the milestones: 8.0.0, 9.0.0 on Jul 24, 2023
  4. changed the title [-][wasm-mt] papercut: Emscripten warns about blocking on the main thread even if user code doesn't[/-] [+][browser][mt] Emscripten warns about blocking on the main thread even if user code doesn't[/+] on Nov 9, 2023
  5. added
    os-browser
    on Nov 9, 2023
  6. pavelsavara commented on Jan 26, 2024

    @pavelsavara
    Member

    I think the message could be supressed in newer versions of emscripten.

    Should we bump version of emscripten ?
    Should we also switch to using https://github.com/dotnet/emscripten/ in our inner loop ?

    @radekdoulik @lewing

  7. changed the title [-][browser][mt] Emscripten warns about blocking on the main thread even if user code doesn't[/-] [+][browser][mt] Upgrade emscripten[/+] on Jan 26, 2024
  8. ilonatommy commented on Jul 25, 2024

    @ilonatommy
    Member

    I think the message could be supressed in newer versions of emscripten.

    Do you mean "The log message that emcc will sometime print (for example when auto-building system libraries) can now be completely suppressed by running with EMCC_LOGGING=0" changelog?

  9. ilonatommy commented on Jul 25, 2024

    @ilonatommy
    Member

    It seems that the situation changed a lot. We have a possibility of config with jsThreadBlockingMode: "WarnWhenBlockingWait" that produces only our own warning from

    var st = $"Blocking the thread with JS interop is dangerous and could lead to deadlock. ManagedThreadId: {Environment.CurrentManagedThreadId}\n{Environment.StackTrace}";
    .
    Even with jsThreadBlockingMode: "DangerousAllowBlockingWait I cannot observe messages from emscripten logged when block-waiting.
    Adding <EmscriptenEnvVars Include="EMCC_LOGGING=0" /> would not change anything. I think we could close it.

  10. pavelsavara commented on Jul 29, 2024

    @pavelsavara
    Member

    We are not running C# code on UI thread anymore and so the user code would not be blocking.
    It could still happen because we stop-the-world during GC.

    jsThreadBlockingMode is about something slightly different.

  11. ilonatommy commented on Jul 29, 2024

    @ilonatommy
    Member

    Reproducing blocking during GC's stop-the-world does not sound like an easy thing. Do you have ideas how to force it? I was planning to check if the logs are there, then add that flag and possibly close the thread.

  12. pavelsavara commented on Jul 29, 2024

    @pavelsavara
    Member

    We can close this one (about emscripten bump).
    The remaining issue will be solved by not blocking UI thread #100411 I updated it to also mention the message

  13. locked and limited conversation to collaborators on Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

arch-wasmarea-VM-threading-monoos-browser

Type

No type

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions