-
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,async_wrap: fixups and fewer aborts #14722
Changes from all commits
f5ef678
0f863d0
f2c1638
14c3a5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,8 @@ inline v8::Local<v8::String> Environment::AsyncHooks::provider_string(int idx) { | |
|
||
inline void Environment::AsyncHooks::push_ids(double async_id, | ||
double trigger_id) { | ||
CHECK_GE(async_id, 0); | ||
CHECK_GE(trigger_id, 0); | ||
CHECK_GE(async_id, -1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is -1 now a special allowed value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. My personal opinion is that those checks should simply be skipped when AsyncHooks isn't used. Relaxing the check when AsyncHooks is used, isn't a good solution. I know that is an unpopular opinion, so I won't block it now, but I really feel we are on a steap slope to some very difficult to debug errors. In the future I want a more detailed discussion about this, unfortunately I don't have time these days. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from commit message body:
we can't guarantee the async id is always assigned properly, and was one reason applications were aborting. history has taught me that it's impossible to make sure the async id is always properly defined because of how much node internals can be abused. so i'm working on one more commit to translate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's not explicitly documented, but one goal of the API was to allow
I fully agree'd with this until I realized how badly node core can be abused by allowing users to pass in arbitrary objects instead of ones created by core constructors (e.g. timers). So it is necessary to coerce, at minimum, async ids of
Again, I fully agree'd with this until I came to terms with the reason pointed out above.
I was thinking about doing something more complex, like
etc. But figured that's too much to anticipate, and wouldn't be worth the time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't document it. I'm on vacation and of all the things I disagree with, our general approach to being robust against implementation errors is what I disagree the most about. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 on keeping this an "internal implementation" detail for now. |
||
CHECK_GE(trigger_id, -1); | ||
|
||
ids_stack_.push({ uid_fields_[kCurrentAsyncId], | ||
uid_fields_[kCurrentTriggerId] }); | ||
|
@@ -176,20 +176,23 @@ inline void Environment::AsyncHooks::clear_id_stack() { | |
inline Environment::AsyncHooks::InitScope::InitScope( | ||
Environment* env, double init_trigger_id) | ||
: env_(env), | ||
uid_fields_(env->async_hooks()->uid_fields()) { | ||
env->async_hooks()->push_ids(uid_fields_[AsyncHooks::kCurrentAsyncId], | ||
uid_fields_ref_(env->async_hooks()->uid_fields()) { | ||
CHECK_GE(init_trigger_id, -1); | ||
env->async_hooks()->push_ids(uid_fields_ref_[AsyncHooks::kCurrentAsyncId], | ||
init_trigger_id); | ||
} | ||
|
||
inline Environment::AsyncHooks::InitScope::~InitScope() { | ||
env_->async_hooks()->pop_ids(uid_fields_[AsyncHooks::kCurrentAsyncId]); | ||
env_->async_hooks()->pop_ids(uid_fields_ref_[AsyncHooks::kCurrentAsyncId]); | ||
} | ||
|
||
inline Environment::AsyncHooks::ExecScope::ExecScope( | ||
Environment* env, double async_id, double trigger_id) | ||
: env_(env), | ||
async_id_(async_id), | ||
disposed_(false) { | ||
CHECK_GE(async_id, -1); | ||
CHECK_GE(trigger_id, -1); | ||
env->async_hooks()->push_ids(async_id, trigger_id); | ||
} | ||
|
||
|
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 perfunctory tests in
test/parallel/test-internal-errors.js
as per https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md#testing-new-errorsThere 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.
done