Skip to content

Fix race condition in browser.test_audioworklet_worker#26839

Merged
juj merged 4 commits intoemscripten-core:mainfrom
juj:fix_sync_logic_in_test_audioworklet_worker
May 2, 2026
Merged

Fix race condition in browser.test_audioworklet_worker#26839
juj merged 4 commits intoemscripten-core:mainfrom
juj:fix_sync_logic_in_test_audioworklet_worker

Conversation

@juj
Copy link
Copy Markdown
Collaborator

@juj juj commented May 1, 2026

Fix race condition in browser.test_audioworklet_worker where worker might miss the wakeup signal that audio worklet has posted.

Update documentation of emscripten_futex_wait() for the different return values the function can have.

@juj juj force-pushed the fix_sync_logic_in_test_audioworklet_worker branch from 5f21da3 to 05ea93f Compare May 1, 2026 19:52
emscripten_outf("Test success (waited %.fms)", emscripten_performance_now() - start);
emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, &do_exit);
break;
}
Copy link
Copy Markdown
Collaborator Author

@juj juj May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old logic:

  1. Main thread races to spawn wasm worker and audio worklet threads.
  2. Let's assume wasm worker thread is slow to start, maybe sleeping for some time before reaching line 23.
  3. Meanwhile, audio worklet thread is faster, and proceeds to execute function MessageReceivedInAudioWorkletThread(), which sets workletToWorkerFlag = true;
  4. Wasm worker thread resumes, and the emscripten_futex_wait() check on line 24 returns immediately with -EWOULDBLOCK since the memory address has value true instead of 0.
  5. The while() loop is not entered, and the function quits without executing lines 26 and 27 at all.

@juj juj enabled auto-merge (squash) May 1, 2026 20:30
@juj juj force-pushed the fix_sync_logic_in_test_audioworklet_worker branch from 991e2cc to c6ba3ee Compare May 2, 2026 07:14
@juj
Copy link
Copy Markdown
Collaborator Author

juj commented May 2, 2026

I rebased this on top of latest main, which is red on CircleCI at the moment on browser.test_audioworklet_worker test.

This PR comes out green, so I'll land this to hopefully get the main branch back to green as well.

If this doesn't help, then the test is flaky in Chrome, and not just consistently failing.

@juj juj disabled auto-merge May 2, 2026 09:32
@juj juj merged commit 8eb2804 into emscripten-core:main May 2, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant