Skip to content
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

Closed
wants to merge 9 commits into from
Closed

async_hooks: C++ Embedder API overhaul #14040

wants to merge 9 commits into from

Conversation

AndreasMadsen
Copy link
Member

@AndreasMadsen AndreasMadsen commented Jul 2, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

async_hooks

I'm not sure how to split up the AsyncHooksGetTriggerAsyncId and the async_context commit. If someone has a specific suggestion I would be happy to do it.

  • 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.

/cc @nodejs/async_hooks

@nodejs-github-bot nodejs-github-bot added async_wrap c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. inspector Issues and PRs related to the V8 inspector protocol labels Jul 2, 2017
@AndreasMadsen AndreasMadsen added addons Issues and PRs related to native addons. async_hooks Issues and PRs related to the async hooks subsystem. semver-minor PRs that contain new features and should be released in the next minor version. dont-land-on-v4.x and removed crypto Issues and PRs related to the crypto subsystem. dont-land-on-v4.x inspector Issues and PRs related to the V8 inspector protocol labels Jul 2, 2017
@AndreasMadsen
Copy link
Member Author

AndreasMadsen commented Jul 2, 2017

I think this is a semver-minor since it only touches async_hooks experimental APIs.

@refack
Copy link
Contributor

refack commented Jul 2, 2017

Does this solve nodejs/help#644?

@addaleax
Copy link
Member

addaleax commented Jul 2, 2017

@refack It’s unlikely, and it’s not really clear what the problem in that issue is in the first place.

@refack
Copy link
Contributor

refack commented Jul 2, 2017

@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 Environment::AsyncHooks::ExecScope being internal, but necessary in order to start the loop.

@addaleax
Copy link
Member

addaleax commented Jul 2, 2017

@refack Can we keep the discussion for that issue in that issue? What you’re saying sounds reasonable, could maybe post a minimal example?

@refack
Copy link
Contributor

refack commented Jul 2, 2017

@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.

Copy link
Member

@addaleax addaleax left a 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 {
Copy link
Member

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);
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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…)

Copy link
Member Author

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 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.

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.

@AndreasMadsen
Copy link
Member Author

AndreasMadsen commented Jul 3, 2017

@AndreasMadsen AndreasMadsen added semver-major PRs that contain breaking changes and should be released in the next major version. and removed semver-minor PRs that contain new features and should be released in the next minor version. labels Jul 3, 2017
Copy link
Member

@addaleax addaleax left a 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!

@AndreasMadsen
Copy link
Member Author

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 {
Copy link
Contributor

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()?

@AndreasMadsen
Copy link
Member Author

AndreasMadsen commented Jul 5, 2017

@trevnorris I renamed the method and added a deprecated alias.

CI: https://ci.nodejs.org/job/node-test-pull-request/8989/

* 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
@AndreasMadsen
Copy link
Member Author

Rebased and added get_trigger_async_id to match the JavaScript version of AsyncResource.

CI: https://ci.nodejs.org/job/node-test-pull-request/8993/

Copy link
Member

@addaleax addaleax left a 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

@AndreasMadsen
Copy link
Member Author

landed in c6ce500

Copy link
Contributor

@refack refack left a 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 👍

addaleax pushed a commit to addaleax/node that referenced this pull request Jul 11, 2017
* 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>
addaleax pushed a commit that referenced this pull request Jul 12, 2017
* 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>
@addaleax addaleax mentioned this pull request Jul 18, 2017
addaleax pushed a commit that referenced this pull request Jul 18, 2017
* 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>
Fishrock123 pushed a commit that referenced this pull request Jul 19, 2017
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Issues and PRs related to native addons. async_hooks Issues and PRs related to the async hooks subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants