-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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: cleanup emitBefore and emitAfter in timers and nextTick #14050
Conversation
CI: https://ci.nodejs.org/job/node-test-pull-request/8962/ |
lib/async_hooks.js
Outdated
if (asyncId < 0 || triggerAsyncId < 0) { | ||
fatalError('before(): asyncId or triggerAsyncId is less than zero ' + | ||
`(asyncId: ${asyncId}, triggerAsyncId: ${triggerAsyncId})`); | ||
} |
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.
This is to throw nicely. If the values make it to AsyncWrap::PushAsyncIds()
then it will abort (i.e. always core dump).
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.
Yes. But does this matter. asyncId < 0
and triggerAsyncId < 0
is for sure not a common error. We can keep the check, but then the performance of nextTick
and the timers won't be exactly the same.
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.
emitBeforeS
is a (undocumented) user API and is exported via require()
. The general rule has been that it shouldn't be possible for the application to abort via any method imported via require()
(this does not hold true for process.binding()
). But removing this allows require('async_hooks').emitBefore(-1, -1)
to cause a CHECK()
failure.
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.
Okay, that makes sense. I will readd the checks later today.
emitBefore(asyncId, triggerAsyncId); | ||
else | ||
pushAsyncIds(asyncId, triggerAsyncId); | ||
} |
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.
History lesson: This was introduced originally because of a crazy method to keep track of the id stack. Which was a lot faster than it is currently, but added an obscene amount of complexity. I hope to simplify that approach in the future and reintroduce it, but seems I overlooked these calls can be removed for the time being.
emitBefore(asyncId, triggerAsyncId); | ||
else | ||
pushAsyncIds(asyncId, triggerAsyncId); | ||
} |
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.
Reason these were here is for the same reason explained in nextTick.
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 want the check in emitBeforeS()
to be removed. Other than that LGTM.
Timers and nextTick have special emitBefore and emitAfter functions for historic reasons. These function are not needed any more, thus the public emitBefore and emitAfter function can be used.
Using asyncId as the default triggerAsyncId is wrong. The triggerAsyncId can actually never be the asyncId.
I reverted the commits that removed the assert and squashed the commits so it isn't confusing. I also rewrote the commit message. |
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.
Thanks for the changes and additional commit message comments. LGTM
Timers and nextTick have special emitBefore and emitAfter functions for historic reasons. These function are not needed any more, thus the public emitBefore and emitAfter function can be used. PR-URL: #14050 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Using asyncId as the default triggerAsyncId is wrong. The triggerAsyncId can actually never be the asyncId. PR-URL: #14050 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Timers and nextTick have special emitBefore and emitAfter functions for historic reasons. These function are not needed any more, thus the public emitBefore and emitAfter function can be used. PR-URL: #14050 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Using asyncId as the default triggerAsyncId is wrong. The triggerAsyncId can actually never be the asyncId. PR-URL: #14050 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Timers and nextTick have special emitBefore and emitAfter functions for historic reasons. These function are not needed any more, thus the public emitBefore and emitAfter function can be used. PR-URL: #14050 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Using asyncId as the default triggerAsyncId is wrong. The triggerAsyncId can actually never be the asyncId. PR-URL: #14050 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
async_hooks, process, timers
async_hooks: use common emitBefore and emitAfter
nextTick
have specialemitBefore
andemitAfter
functions forperformance reasons. But if the assert in
async_hooks.emitBefore
isremoved there is no difference.
edit: the checks are already included in
pushAsyncIds
.async_hooks: require parameter in emitBefore
asyncId
as the defaulttriggerAsyncId
is wrong. ThetriggerAsyncId
can actually never be the
asyncId
./cc @nodejs/async_hooks