-
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
async_hooks: clean up usage in internal code #18720
Conversation
/cc @addaleax, @ofrobots, @AndreasMadsen — I would appreciate a review from someone involved with async hooks. Want to make sure I'm not missing anything, in particular with moving the symbols to |
Apologies for the delay. I have been busy with the diagnostic summit. I
will take a look tomorrow.
…On Tue, Feb 13, 2018, 7:37 PM Anatoli Papirovski ***@***.***> wrote:
/cc @addaleax <https://github.com/addaleax>, @ofrobots
<https://github.com/ofrobots>, @AndreasMadsen
<https://github.com/andreasmadsen> — I would appreciate a review from
someone involved with async hooks. Want to make sure I'm not missing
anything, in particular with moving the symbols to internal/async_hooks
(if they're meant to be quasi-public — as they were via process.binding —
then they should probably be exported from async_hooks to be honest).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18720 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAE0qXKnJcc94uCMWI91_eeC9ZuV2zuTks5tUirfgaJpZM4SBi6R>
.
|
@ofrobots No worries :) Hope the summit was productive, disappointed I had to miss it. |
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 w/ nits. Thanks for doing all this cleanup!
return async_id_fields[kExecutionAsyncId]; | ||
} | ||
|
||
|
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.
nit: executionAsyncId
and triggerAsyncId
should probably stay together. Either both move or neither.
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.
Works for me. I'll move both. (I wanted to avoid requiring both files during bootstrap.)
lib/internal/async_hooks.js
Outdated
@@ -345,6 +365,18 @@ function emitDestroyScript(asyncId) { | |||
} | |||
|
|||
|
|||
function clearAsyncIdStack() { |
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.
nit: needs a comment that needs to stay in sync with the C++ copy in env-inl.h
(and vice versa).
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.
Good point. Will update!
@@ -270,6 +272,11 @@ function getDefaultTriggerAsyncId() { | |||
} | |||
|
|||
|
|||
function clearDefaultTriggerAsyncId() { |
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.
nit: It might be worth moving the copy of this operation in env-inl.h
into a standalone create_default_trigger_async_id
function so that we can attach a comment in both places to keep the copies in sync.
Aside: I've wanted to cleanup the magical -1 and 0 hard-coded constants for async id, but that should probably happen in a separate PR.
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 don't know if it makes sense to move it off into a function in C++ since it seems to only be done from the constructor. Perhaps a constant makes the most sense.
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.
Could you add a comment that says that this should never be used except for exception handling?
@ofrobots Updated now. Thanks for the feedback! |
@addaleax Would you mind reviewing this? Looking to land today but there's one commit that hasn't been reviewed. Thanks! |
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.
Looks fine to me :)
emitInit | ||
} = require('internal/async_hooks'); | ||
// Grab the constants necessary for working with internal arrays. | ||
const { kInit, kAsyncIdCounter } = async_wrap.constants; | ||
// Symbols for storing async id state. | ||
const async_id_symbol = Symbol('asyncId'); |
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.
Why do we have separate symbols for this? 😂 I think they should just be async_id_symbol
and trigger_async_id_symbol
from async_hooks
.
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.
Funny enough, it's actually necessary because of enroll and unenroll. Since they could use an object that already has an asyncId associated, it would overwrite it or misrepresent it in emit.
lib/internal/async_hooks.js
Outdated
init_symbol, before_symbol, after_symbol, destroy_symbol, | ||
promise_resolve_symbol | ||
}, | ||
enableHooks, | ||
disableHooks, | ||
clearDefaultTriggerAsyncId, | ||
clearAsyncIdStack, | ||
hasAsyncIdStack, | ||
// Internal Embedder API | ||
newUid, |
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.
nit: You would be truly loved if you renamed this to newAsyncId
:)
Instead of exposing internals of async_hooks & async_wrap throughout the code base, create necessary helper methods within the internal async_hooks that allows easy usage by Node.js internals. This stops every single internal user of async_hooks from importing a ton of functions, constants and internal Aliased Buffers from C++ async_wrap. Adds functions initHooksExist, afterHooksExist, and destroyHooksExist to determine whether the related emit methods need to be triggered. Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side as an alternative to always calling C++. Moves async_id_symbol and trigger_async_id_symbol to internal async_hooks as they are never used in C++. Adjusts usage throughout the codebase, as well as in a couple of tests.
Lite CI before landing: https://ci.nodejs.org/job/node-test-pull-request-lite/175/ |
13f1c56
to
b400c80
Compare
b400c80
to
2abd4a7
Compare
Instead of exposing internals of async_hooks & async_wrap throughout the code base, create necessary helper methods within the internal async_hooks that allows easy usage by Node.js internals. This stops every single internal user of async_hooks from importing a ton of functions, constants and internal Aliased Buffers from C++ async_wrap. Adds functions initHooksExist, afterHooksExist, and destroyHooksExist to determine whether the related emit methods need to be triggered. Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side as an alternative to always calling C++. Moves async_id_symbol and trigger_async_id_symbol to internal async_hooks as they are never used in C++. Renames newUid to newAsyncId for added clarity of its purpose. Adjusts usage throughout the codebase, as well as in a couple of tests. PR-URL: #18720 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Landed in e9ac80b |
Instead of exposing internals of async_hooks & async_wrap throughout the code base, create necessary helper methods within the internal async_hooks that allows easy usage by Node.js internals. This stops every single internal user of async_hooks from importing a ton of functions, constants and internal Aliased Buffers from C++ async_wrap. Adds functions initHooksExist, afterHooksExist, and destroyHooksExist to determine whether the related emit methods need to be triggered. Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side as an alternative to always calling C++. Moves async_id_symbol and trigger_async_id_symbol to internal async_hooks as they are never used in C++. Renames newUid to newAsyncId for added clarity of its purpose. Adjusts usage throughout the codebase, as well as in a couple of tests. PR-URL: nodejs#18720 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Should this be backported to |
Instead of exposing internals of async_hooks & async_wrap throughout
the code base, create necessary helper functions within the internal
async_hooks that allow easy usage by Node.js internals. This stops
every single internal user of async_hooks from importing a ton of
functions, constants and internal Aliased Buffers from C++ async_wrap.
Adds functions initHooksExist, afterHooksExist, and destroyHooksExist
to determine whether the related emit methods need to be triggered.
Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side
as an alternative to always calling C++.
Moves async_id_symbol and trigger_async_id_symbol to internal
async_hooks as they are never used in C++.
Adjusts usage throughout the codebase, as well as in a couple of tests.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
async_hooks