-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Revisit unrefed handles and beforeExit
internals
#3665
Comments
A libuv test which fails on the offending platform would help here. I quickly check when we run the close callbacks and we do it at the same point in time on Unix and Windows, so the issue might be a little non-obvious. |
@saghul This isn't about a specific platform. Trying to fix the (patched in JavaScript ala #3407) bug exposed something that was, but this is questioning if something deeper isn't wrong. Either that or that we all deeply misunderstand something. Since the old problems existed independently of platform (as far as I know) and that the current code works ok on all platforms suggests this isn't platform specific. |
@Fishrock123 The fix we had of walking all active handles and checking the active handle count was different on unix than it was windows. |
@trevnorris right, I'm pointing out that logically the original failure should never have happened; two+ |
@Fishrock123 sorry, this slipped somewhere to the side on my inbox. So, in a nutshell, reverting the fix in #3407 the test case will fail but it shouldn't, right? If so I'll take a look. |
@saghul If I understand the logic correctly as laid out in my OP, yes. Again, smells like a |
@saghul were you ever able to take a look here? :) |
Not yet, sorry :-S |
This conversation has been dormant for over a year. Is this something that should be closed? |
Probably not. Someone should look into it in more detail at some point. We're working around it but the behavior is suspicious, though not outright buggy. |
On second thought, maybe it would be possible to craft a |
Node.js currently uses the V8 implementation of the DefaultPlatform which schedules VM tasks on a V8 managed thread pool. Since the Node.js event loop is not aware of these tasks, the Node.js process may exit while there are outstanding VM tasks. This will become problematic once asynchronous wasm compilation lands in V8. This PR introduces a Node.js specific implementation of the v8::Platform on top of libuv so that the event loop is aware of outstanding VM tasks. PR-URL: #14001 Fixes: #3665 Fixes: #8496 Fixes: #12980 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Node.js currently uses the V8 implementation of the DefaultPlatform which schedules VM tasks on a V8 managed thread pool. Since the Node.js event loop is not aware of these tasks, the Node.js process may exit while there are outstanding VM tasks. This will become problematic once asynchronous wasm compilation lands in V8. This PR introduces a Node.js specific implementation of the v8::Platform on top of libuv so that the event loop is aware of outstanding VM tasks. PR-URL: #14001 Fixes: #3665 Fixes: #8496 Fixes: #12980 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Node.js currently uses the V8 implementation of the DefaultPlatform which schedules VM tasks on a V8 managed thread pool. Since the Node.js event loop is not aware of these tasks, the Node.js process may exit while there are outstanding VM tasks. This will become problematic once asynchronous wasm compilation lands in V8. This PR introduces a Node.js specific implementation of the v8::Platform on top of libuv so that the event loop is aware of outstanding VM tasks. PR-URL: #14001 Fixes: #3665 Fixes: #8496 Fixes: #12980 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
The original issue is at #1264
The synopsis is that because of how
uv_run
works, unrefed handles show up as active still for the first run, and don't appear as no-longer active until the second run.In the past, running an unrefed timer in
beforeExit
would infinitely loop, since the second run would always be in the nextbeforeExit
, consequentially calling'beforeExit'
again and scheduling another time, looping infinitely. This was fixed in #3407 by making unrefed timers of the same timeout use the previous handle, which is then properly unreferenced.As described, one would expect the event loop / beforeExit code to look something like so:
However in reality it looks more like this:
(
node/src/node.cc
Lines 4063 to 4078 in 471aa5a
If you look closely at the actual version, you'll notice that
uv_run
ends up actually being called at least 2 times on abeforeExit
re-entry anyways, which logically register the timer and unref. However it does not seem to work like that.Sniff test says it may be some discrepancy within
uv_run
modes?cc @indutny, @trevnorris, @saghul
The text was updated successfully, but these errors were encountered: