-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix macros which call Bun.file operations causing build commands to hang #15991
base: main
Are you sure you want to change the base?
Conversation
9531a76
to
43530a5
Compare
43530a5
to
3dd728a
Compare
I guess things are never this easy... |
My guess is that by not using the bundler’s threadpool, the threads never call their init function it sounds like we should have a global variable for “threadpool ID” and only use the global one in that case maybe? |
3dd728a
to
c4d2ed4
Compare
dbf3170
to
e884ee1
Compare
Sorry about the failures. The additional Windows failure may indicate that this is a race condition of some sort. I searched the codebase for additional direct uses of Again, sorry about the test failures! |
e884ee1
to
9b0e556
Compare
6ffdf04
to
a07bb13
Compare
a07bb13
to
60e785c
Compare
@Jarred-Sumner This would have been fine, except there’s a bug in Lines 416 to 435 in 7830e15
In short, Line 169 in 7830e15
|
What does this PR do?
Users reported in #7611 and #14104 that calling
Bun.file().text()
in a macro would cause builds to hang. This bug was introduced in v1.0.16, likely when some changes related to how Bun handles multithreading occurred.I went through a minimal reproduction with a debugger and determined that work would get stuck in ThreadPool threads because the ThreadPool was initialized twice. The double instantiation of ThreadPool, which is assumed to be a global singleton, caused issues in macros because file I/O would get scheduled on a thread, the work would be pushed to the thread local queue/buffer, and then the thread would wait for the promise to resolve, causing a dead lock. There is code which allows for “work stealing” but threads initialized from different thread pools do not steal work each other.
The least invasive fix I found was to consistently call
WorkPool.get()
in the bundle_v2’s initialization code.Fixes #7611 and fixes #14104.
Happy holidays!
How did you verify your code works?
bun-debug test test-file-name.test
)