Skip to content

fix: use Mutex<Arc<tokio::sync::OnceCell<JsLoaderRunner>>> to avoid loader runner deadlock #10632

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

Merged
merged 3 commits into from
Jun 11, 2025

Conversation

CPunisher
Copy link
Contributor

@CPunisher CPunisher commented Jun 11, 2025

Summary

There could be a deadlock risk with the original implementation. Consider the following execution sequence:

  1. Assume both of threads T1 and T2 get the runner read locks, which contains None.
  2. T1 get the write runner lock, and create a runner.
  3. T1 get the read runner lock and run runner.call_async, which yields to js loaders.
  4. One of the js loaders call loaderContext.importModule and append a task to module_executor in (assumed) T3. So T1 should wait for T3.
  5. T3 will also run their js loaders. Assume T2 request the runner write lock before T3 request runner read lock. Due to the priority policy of tokio::sync::RwLock (https://docs.rs/tokio/latest/tokio/sync/struct.RwLock.html), T3 will not get the read lock before T2 get the write lock.
  6. While T1 is holding the read lock, T2 is pending and cannot get the write lock.
  7. In conclusion: T1 waits for T3 because of (importModule), T2 waits for T1 to release its read lock, T3 waits for T2 to acquire and release the write lock.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Jun 11, 2025

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit e93ab54
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6848f11f981ce10008aa0aa3

@github-actions github-actions bot added the release: bug fix release: bug related release(mr only) label Jun 11, 2025
@CPunisher CPunisher marked this pull request as ready for review June 11, 2025 02:58
Copy link

codspeed-hq bot commented Jun 11, 2025

CodSpeed Performance Report

Merging #10632 will not alter performance

Comparing CPunisher:06-11-fix/rwlock-deadlock (e93ab54) with main (9a7efa3)

🎉 Hooray! codspeed-rust just leveled up to 2.7.2!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 12 untouched benchmarks

@CPunisher CPunisher merged commit 9b2f4d9 into web-infra-dev:main Jun 11, 2025
34 checks passed
@CPunisher CPunisher deleted the 06-11-fix/rwlock-deadlock branch June 11, 2025 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: bug fix release: bug related release(mr only)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy