-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
src: add HandleScope to fix error #19972
Conversation
Add `HandleError`s to the AsyncScope constructor and destructor in async_wrap-inl.h to fix "FATAL ERROR" incurring observed while running test-http2-respond-with-file using the --trace-events-enabled flag. Fixes: nodejs#19921
I'm also testing this locally. Meanwhile, could you help me understand what exactly was wrong and how it was fixed by adding the two |
The error says: |
@ryzokuken When accessing JS values from C++, what the engine provides in order to to that is a handle object, i.e. As an optimization, these handles do not directly manage the lifetime of JS objects, like one might expect from C++ objects. Instead, V8 uses the concept of a handle scope: These form a stack, and new handles are always added to the scope on top of the stack. That scope is basically a GC root – all JS objects that are registered with it are kept alive, until the scope is closed. In Node.js, if our code is called from e.g. libuv, we need such a scope that is inside of the callback. Otherwise, any JS object we’re creating or getting a reference to in some other way, would be registered in a scope that is outside of the event loop. That would mean that these objects cannot be garbage-collected until the event loop finishes, creating a memory leak. (Having an error instead of a memory leak was implemented because it made checking for these kinds of leaks inside Node.js easier, btw.)
According to the stack trace from #19921, that would be the It might make more sense to add the handle scope there, because that’s where they are being used. However, while |
Add `HandleError`s to the AsyncScope constructor and destructor in async_wrap-inl.h to fix "FATAL ERROR" incurring observed while running test-http2-respond-with-file using the --trace-events-enabled flag. Fixes: #19921 PR-URL: #19972 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 6eaeabc |
Guess I saw this too late. Current solution works. But I would just put a |
@hashseed yes, that sounds great too, but I wonder: do we need |
Yes. |
@hashseed that makes a lot of sense. Forgive me for the noobish question, but what if |
@ryzokuken You end up with two nested If you create two handle scopes immediately after one another, the effect will be the same as if there was only one – there just won’t be any handles associated with the outer one. |
What Anna said. Having a nested handle scope is fine. |
@addaleax @hashseed In that case, calling So, what do you say? Should I also add a call inside |
I mean, if @hashseed says it’s fine from a performance point of view, I believe that. :) You can feel free to make that switch. |
Sounds like a plan :) |
Add `HandleError`s to the AsyncScope constructor and destructor in async_wrap-inl.h to fix "FATAL ERROR" incurring observed while running test-http2-respond-with-file using the --trace-events-enabled flag. Fixes: #19921 PR-URL: #19972 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Remove redundant calls to v8::HandleScope in the contructor and destructor for the AsyncScope class Refs: nodejs#19972 (comment) Refs: nodejs#20045
Move v8::HandleScope call to Emit removing it from previous locations where it was added to avoid crashing (constructor and destructor of AsyncWrap) for a more general and fool-proof solution. Ref: nodejs#19972 (comment)
Move v8::HandleScope call to Emit removing it from previous locations where it was added to avoid crashing (constructor and destructor of AsyncWrap) for a more general and fool-proof solution. Ref: #19972 (comment) PR-URL: #20045 Reviewed-By: Yang Guo <yangguo@chromium.org> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Move v8::HandleScope call to Emit removing it from previous locations where it was added to avoid crashing (constructor and destructor of AsyncWrap) for a more general and fool-proof solution. Ref: #19972 (comment) PR-URL: #20045 Reviewed-By: Yang Guo <yangguo@chromium.org> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Add
HandleError
s to the AsyncScope constructor and destructor inasync_wrap-inl.h to fix "FATAL ERROR" incurring observed while running
test-http2-respond-with-file using the --trace-events-enabled flag.
Fixes: #19921
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passescc @addaleax @jasnell