-
Notifications
You must be signed in to change notification settings - Fork 30k
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
module: prevent main thread exiting before esm worker ends #56183
module: prevent main thread exiting before esm worker ends #56183
Conversation
Review requested:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #56183 +/- ##
==========================================
+ Coverage 88.01% 88.49% +0.48%
==========================================
Files 656 656
Lines 189136 189263 +127
Branches 36004 36348 +344
==========================================
+ Hits 166461 167497 +1036
+ Misses 15842 14977 -865
+ Partials 6833 6789 -44
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with a nit
Co-authored-by: Matteo Collina <[email protected]>
Sorry I'm swamped this week. This sounds like something we tried back when that led to a deadlock in some circumstances. I was going to ask Antoine, who I think worked on that specific scenario with me; I see he has reviewed this though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of the specific issue; we surely would have added a test-case for it before landing, so if the tests are passing, it should be okay!
Thanks for this!
Does this also address console.logs getting "lost"? If so, the API docs should to be updated to remove the caveat. I think that should happen in this PR for an atomic change.
Landed in 2063245 |
Sorry for the delayed response.
I made the change to lock the main thread until handleMessage completes, but I overlooked asynchronous considerations. |
PR-URL: #56183 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
This fix ensures the main thread does not terminate before an ESM worker's
handleMessage
function completes by moving the atomic lock release to the end of the function. As far as I can see, there doesn’t seem to be any necessary processing after the lock release.Problem
The
test-esm-loader-spawn-promisified.mjs
test occasionally fails in debug builds. If processing after the lock release exceeds the stack limit, it results in a fatal error:Even if it fails in a debug build, it is desirable for the error to be a JavaScript error, such as Maximum call stack size exceeded, rather than a debug check error.
Although it involves modifying the internal code, the issue can be reproduced as follows:
Test
Testing this precisely is difficult due to timing sensitivity. A new test verifies that a deliberate stack overflow results in the correct
Maximum call stack size exceeded
error, ensuring the lock behavior is correct.