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

Deadlock in dedicated worker #32

Open
sinui0 opened this issue Feb 24, 2025 · 0 comments
Open

Deadlock in dedicated worker #32

sinui0 opened this issue Feb 24, 2025 · 0 comments

Comments

@sinui0
Copy link

sinui0 commented Feb 24, 2025

I've encountered an unexpected deadlock when using wasm_thread in a binary running directly in a dedicated web worker.

It can be reproduced reliably as demonstrated here.

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_dedicated_worker);

#[wasm_bindgen_test]
fn test_thread_join() {
    let handle = thread::spawn(|| 1234);

    assert_eq!(handle.join().unwrap(), 1234);
}

After some digging I believe the deadlock stems from here

if is_web_worker_thread() {
WorkerMessage::SpawnThread(BuilderRequest { builder: self, context }).post();
} else {
self.spawn_for_context(context);
}

is_web_worker_thread will evaluate to true, which will post a message to the parent page which has no handler for it.

spawn_for_context must be called at least once regardless of whether it is a worker or the browser main thread. This can possibly be addressed by adding a global and changing it to this:

if is_main_thread() { 
    self.spawn_for_context(context);
} else { 
    WorkerMessage::SpawnThread(BuilderRequest { builder: self, context }).post();
}
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

No branches or pull requests

1 participant