-
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: C++ Embedder API overhaul #14040
async_hooks: C++ Embedder API overhaul #14040
Conversation
I think this is a semver-minor since it only touches |
Does this solve nodejs/help#644? |
@refack It’s unlikely, and it’s not really clear what the problem in that issue is in the first place. |
AFAICT the issue there is |
@refack Can we keep the discussion for that issue in that issue? What you’re saying sounds reasonable, could maybe post a minimal example? |
Sure. |
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.
Mostly looks good from a quick glance!
src/node.h
Outdated
@@ -517,7 +517,11 @@ typedef void (*promise_hook_func) (v8::PromiseHookType type, | |||
v8::Local<v8::Value> parent, | |||
void* arg); | |||
|
|||
typedef double async_uid; | |||
typedef double async_id; | |||
typedef struct async_context { |
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.
Fwiw you don’t need a typedef, just struct async_context { ... };
will work fine.
NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate, | ||
v8::Local<v8::Object> resource, | ||
const char* name, | ||
async_id trigger_async_id = -1); |
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.
It seems to me like this breakage would be shim-able… If that’s right, I’d say we label this dont-land and I can do a non-breaking backport to v8.x, if you like
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.
That would be awesome. In particular, I couldn't see how to make EmitAsyncInit
backward compatible.
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.
The old API required trigger_async_id
instead of leaving it optional, so we could make it return a pair based on that parameter, right?
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.
What should EmitAsyncInit
then return when trigger_async_id
is specified?
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 really understand the question, sorry. Basically, what we need to shim is the old definition
async_uid EmitAsyncInit(v8::Isolate* isolate,
v8::Local<v8::Object> resource,
const char* name,
async_uid trigger_async_id);
in terms of the new one in this PR, right?
So what’s speaking against OldStyleEmitAsyncInit(resource, name, trigger_async_id) := (NewStyleAsyncInit(resource, name, trigger_async_id)).async_id_
?
Or are you thinking about the return type? The hacky solution would be to enable casting from async_context
to async_id
by returning async_id_
(and immediately deprecating that), it’s not pretty but as long as it doesn’t end up in master I’m okay with that.
(One more thing: I’m noticing, maybe we should not underscore-suffix the fields of async_context
given that they are public, not internal…)
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.
Or are you thinking about the return type? The hacky solution would be to enable casting from
async_context
toasync_id
by returningasync_id_
(and immediately deprecating that), it’s not pretty but as long as it doesn’t end up in master I’m okay with that.
Yes, it is the return type. The casting makes sense.
(One more thing: I’m noticing, maybe we should not underscore-suffix the fields of
async_context
given that they are public, not internal…)
Right. Please check ffdd431d7d42efe939f3cc378814844b5796e4b5.
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.
Once again thank you for all your hard work. LGTM!
src/node.h
Outdated
} | ||
|
||
v8::Local<v8::Object> get_resource() { | ||
return resource_.Get(isolate_); | ||
} | ||
|
||
async_uid get_uid() const { | ||
return uid_; | ||
async_id get_uid() const { |
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.
For the sake of keeping things the same, want to rename this to get_async_id()
?
@trevnorris I renamed the method and added a deprecated alias. |
* Fix AsyncHooksGetTriggerAsyncId such it corresponds to async_hooks.triggerAsyncId and not async_hooks.initTriggerId. * Use an async_context struct instead of two async_uid values. This change was necessary since the fixing AsyncHooksGetTriggerAsyncId otherwise makes it impossible to get the correct default trigger id. It also prevents an invalid triggerAsyncId in MakeCallback. * Rename async_uid to async_id for consistency async_hooks: fix AsyncHooksGetTriggerAsyncId
Rebased and added |
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.
Just making it it explicit that this still LGTM
landed in c6ce500 |
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.
An After the fact 👍
* Fix AsyncHooksGetTriggerAsyncId such it corresponds to async_hooks.triggerAsyncId and not async_hooks.initTriggerId. * Use an async_context struct instead of two async_uid values. This change was necessary since the fixing AsyncHooksGetTriggerAsyncId otherwise makes it impossible to get the correct default trigger id. It also prevents an invalid triggerAsyncId in MakeCallback. * Rename async_uid to async_id for consistency * Rename get_uid to get_async_id * Add get_trigger_async_id to AsyncResource class PR-URL: nodejs#14040 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
* Fix AsyncHooksGetTriggerAsyncId such it corresponds to async_hooks.triggerAsyncId and not async_hooks.initTriggerId. * Use an async_context struct instead of two async_uid values. This change was necessary since the fixing AsyncHooksGetTriggerAsyncId otherwise makes it impossible to get the correct default trigger id. It also prevents an invalid triggerAsyncId in MakeCallback. * Rename async_uid to async_id for consistency * Rename get_uid to get_async_id * Add get_trigger_async_id to AsyncResource class PR-URL: #14040 Backport-PR-URL: #14109 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* Fix AsyncHooksGetTriggerAsyncId such it corresponds to async_hooks.triggerAsyncId and not async_hooks.initTriggerId. * Use an async_context struct instead of two async_uid values. This change was necessary since the fixing AsyncHooksGetTriggerAsyncId otherwise makes it impossible to get the correct default trigger id. It also prevents an invalid triggerAsyncId in MakeCallback. * Rename async_uid to async_id for consistency * Rename get_uid to get_async_id * Add get_trigger_async_id to AsyncResource class PR-URL: #14040 Backport-PR-URL: #14109 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* Fix AsyncHooksGetTriggerAsyncId such it corresponds to async_hooks.triggerAsyncId and not async_hooks.initTriggerId. * Use an async_context struct instead of two async_uid values. This change was necessary since the fixing AsyncHooksGetTriggerAsyncId otherwise makes it impossible to get the correct default trigger id. It also prevents an invalid triggerAsyncId in MakeCallback. * Rename async_uid to async_id for consistency * Rename get_uid to get_async_id * Add get_trigger_async_id to AsyncResource class PR-URL: #14040 Backport-PR-URL: #14109 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
async_hooks
I'm not sure how to split up the
AsyncHooksGetTriggerAsyncId
and theasync_context
commit. If someone has a specific suggestion I would be happy to do it.AsyncHooksGetTriggerAsyncId
such it corresponds toasync_hooks.triggerAsyncId
and notasync_hooks.initTriggerId
.async_context
struct instead of twoasync_uid
values. This change was necessary since the fixingAsyncHooksGetTriggerAsyncId
otherwise makes it impossible to get the correct default trigger id. It also prevents an invalidtriggerAsyncId
inMakeCallback
.async_uid
toasync_id
for consistency./cc @nodejs/async_hooks