-
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
Platform thread race: process.exit executed before background threads are ready #23065
Comments
Okay, it seems that Unix platforms are a lot faster in the time between This happens on windows but seems to be a general problem with how we are doing background threads in Node. I think the right answer would be for the main thread to wait for the background threads to be initialized before executing user code, but I am interested in other opinions. /cc @addaleax @jasnell @nodejs/libuv. |
I think you're right. Initializing the background threads should complete before progressing forward with any bootstrap or post-bootstrap execution of any code that may trigger a process.exit |
That seems like a good idea, but it sounds like it could affect Windows startup performance significantly? In the case of libuv, we do wait until all threads in the pool have spawned, and on non-Windows additionally wait for them to |
@addaleax I doubt this will affect startup performance significantly anywhere. I can measure. I think this should be done on all platforms. We have only seen this manifest on windows so far, but there the race exists on all platforms. It would not be safe to give control to any bootstrap code while the background worker threads are still initializing. |
While implementing a fix, I ran into a bug in libuv thread synchronization primitives on mac. This is currently blocked on libuv/libuv#2003. |
Make sure background workers are ready before proceeding with the bootstrap or post-bootstrap execution of any code that may trigger `process.exit()`. Fixes: nodejs#23065
@addaleax I did some measurements using this benchmark: https://gist.github.com/ofrobots/f686aa7bc33b21e9c09bece53bb8bf52. This runs Baseline (no thread sync on startup):
With a thread sync on startup:
Based on this there is no evidence of noticeable impact on startup. I get similar data on my Mac laptop (interestingly, we are 2x faster starting up on a Mac. This may be something worth chasing down at some point... ) Commits under test:
|
Make sure background workers are ready before proceeding with the bootstrap or post-bootstrap execution of any code that may trigger `process.exit()`. Fixes: nodejs#23065
Make sure background workers are ready before proceeding with the bootstrap or post-bootstrap execution of any code that may trigger `process.exit()`. Fixes: nodejs#23065 PR-URL: nodejs#23233 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Fixed in e273abc |
Make sure background workers are ready before proceeding with the bootstrap or post-bootstrap execution of any code that may trigger `process.exit()`. Fixes: nodejs#23065 PR-URL: nodejs#23233 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Make sure background workers are ready before proceeding with the bootstrap or post-bootstrap execution of any code that may trigger `process.exit()`. Fixes: #23065 PR-URL: #23233 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Make sure background workers are ready before proceeding with the bootstrap or post-bootstrap execution of any code that may trigger `process.exit()`. Fixes: #23065 PR-URL: #23233 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Make sure background workers are ready before proceeding with the bootstrap or post-bootstrap execution of any code that may trigger `process.exit()`. Fixes: #23065 PR-URL: #23233 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Make sure background workers are ready before proceeding with the bootstrap or post-bootstrap execution of any code that may trigger `process.exit()`. Fixes: #23065 PR-URL: #23233 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Make sure background workers are ready before proceeding with the bootstrap or post-bootstrap execution of any code that may trigger `process.exit()`. Fixes: #23065 PR-URL: #23233 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Forked issue from #22938 (comment).
This test case:
Intermittently crashes in the child process on windows when a small IO delay is introduced in the platform worker thread startup:
Crash:
The platform worker thread is trying to do IO while the main thread is already shutting things down in
exit
./cc @nodejs/platform-windows
The text was updated successfully, but these errors were encountered: