Skip to content

Couple of flaky pthread tests on Firefox #18307

Closed

Description

@RReverser

I'm commonly seeing these 5 tests in particular failing on the CI in Firefox, and working after couple of attempts:

  • test_pthread_sbrk
  • test_pthread_safe_stack
  • test_pthread_run_script
  • test_pthread_run_on_main_thread_flood
  • test_pthread_run_on_main_thread

Here's an example log from recently seen failures (attaching as a file because I'm not sure about retention duration on CircleCI):
log.txt

Activity

  1. RReverser commented on Dec 2, 2022

    @RReverser
    CollaboratorAuthor

    Maybe sbrk is related to #10006? It was closed as stale, but I guess it's still an issue that, for whatever reason, manifests in Firefox more frequently than elsewhere.

    Doesn't explain others though.

  2. RReverser commented on Dec 2, 2022

    @RReverser
    CollaboratorAuthor

    OTOH I wonder if it's something that would be accidentally fixed by my changes in #18305.

    One of the things I noticed and had to do there is manually start executing messages only after Module variable has been definitely assigned. It became a pretty noticeable issue in Firefox due to my changes to postMessage scheduling in the same PR, but now I wonder if there was always a racy issue, just less noticeable before.

    A bit suspiciously, that PR also passed on the first run, but it still might be all a coincidence...

  3. RReverser commented on Dec 2, 2022

    @RReverser
    CollaboratorAuthor

    Although no, that should've affected only modularize builds, and those tests are not it...

  4. RReverser commented on Dec 2, 2022

    @RReverser
    CollaboratorAuthor

    OTOH I wonder if it's something that would be accidentally fixed by my changes in #18305.

    Just tested that theory by extracting those changes separately and, no, that doesn't help. Must be some other reason, although I don't see what's common between specifically those 5 tests.

  5. kleisauke commented on Dec 2, 2022

    @kleisauke
    Collaborator

    Looking at the log, I think(?) that test_pthread_run_on_main_thread makes the whole browser unresponsive, causing subsequent tests to fail as well. Which explains that this is only a issue on Firefox, because on Chrome this test is already disabled (see commit 6ea085c).

    As for a possible fix, perhaps commit 25a6cb2 in PR #13007 would fix this? Just a wild guess, it's based upon that this test makes heavily use of those helpers in <emscripten/threading.h>, which would end-up calling emscripten_wait_for_call_v() in most cases.

    That PR also includes some other goodies, such as commit fd05b36. Sorry for not further upstreaming those commits, I sometimes have limited spare-time. :(

  6. kleisauke commented on Dec 2, 2022

    @kleisauke
    Collaborator

    ... as always, I could certainly use some help in upstreaming these patches. FWIW, I'm currently tracking this in the "Upstream patches" card at Stable release for wasm-vips.

  7. kleisauke commented on Dec 2, 2022

    @kleisauke
    Collaborator

    As for a possible fix, perhaps commit 25a6cb2 in PR #13007 would fix this?

    Though, I think the intention of PR #15681 was to deprecate emscripten_wait_for_call_v() in favor of the proposed APIs mentioned in comment #15705 (comment).

  8. RReverser commented on Dec 2, 2022

    @RReverser
    CollaboratorAuthor

    As for a possible fix, perhaps commit 25a6cb2 in PR #13007 would fix this?

    Though, I think the intention of PR #15681 was to deprecate emscripten_wait_for_call_v() in favor of the proposed APIs mentioned in comment #15705 (comment).

    Ok I'm not familiar with that side of the things so tagging @tlively.

  9. added a commit that references this issue on Dec 3, 2022
    ff3cf7b
  10. added a commit that references this issue on Dec 3, 2022
    6d6344d
  11. tlively commented on Dec 6, 2022

    @tlively
    Member

    emscripten_wait_for_call_v should be implemented in terms of the new proxying API (with the system proxying queue), so it's not inherently bad to use, but should only be used for things that act like signal handlers. Looking at the test_pthread_run_on_main_thread test, it looks like it's calling printf, which internally acquires locks. My guess is that printfs are racing, and when one acquires the lock, the system proxying queue is pumped and another starts running in the middle of the first, so the main thread is deadlocking on itself.

  12. RReverser commented on Dec 11, 2022

    @RReverser
    CollaboratorAuthor

    Looks like test_pthread_proxying_cpp is also flaky, probably for similar reasons. A bit hard to tell as that test seems to combine several in one file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions