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

process: use owner symbol to access more public APIs in _getActive* #22002

Closed
wants to merge 4 commits into from

Conversation

addaleax
Copy link
Member

Use a standardized owner_symbol key to access the corresponding “public” JS wrapper object for a native handle. Currently, this is only implemented for the objects that already had some sort of owner keys, but this should be a first step towards making this a more common pattern.

/cc @nodejs/diagnostics

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Jul 27, 2018
@addaleax addaleax added the process Issues and PRs related to the process subsystem. label Jul 27, 2018
Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maclover7
Copy link
Contributor

I forget if there's a deprecation process for to remove strings from Environment, but looks like the last two use cases for env->owner_string() are removed here, so that could possibly be ✂️as well

@addaleax
Copy link
Member Author

@maclover7 env.h has NODE_WANT_INTERNALS guards, it’s private API and we don’t need to worry about that. I’ve removed them, thanks for catching that 🙂

CHECK(!obj.IsEmpty());

v8::TryCatch ignore_exceptions(env->isolate());
while (true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if we have a pathological case of cyclic ownership?

a[owner_symbol] = b;
b[owner_symbol] = a;

Is there a cycle safe STL algorithm for such a recursive walk?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s going to run into an infinite loop, yes.

Is there a cycle safe STL algorithm for such a recursive walk?

No, but you could implement something like a set of seen objects. The performance impact would be very noticeable, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just limit the loop to an arbitrary number of iterations and crash. IMHO better than a infinite busy loop, but I have no strong feelings about this.

@AndreasMadsen
Copy link
Member

This is awesome, does this mean we can also start exposing the owner resource as the async_hooks resource?

@jasnell
Copy link
Member

jasnell commented Jul 27, 2018

This is awesome, does this mean we can also start exposing the owner resource as the async_hooks resource?

Certainly safer to do so. I still think it may be worthwhile exploring a minimal shared interface for such resources, but I'd be much happier exposing the owner than the handle.

@addaleax
Copy link
Member Author

@AndreasMadsen @jasnell I’d really like that (and the fact that GetOwner() methods are being introduced here are a step towards it), but it’s not happening in this PR at least because the native handles are constructed before the property can be set on them. I think it’s doable but not trivial to make that work.

@BridgeAR
Copy link
Member

This needs a rebase.

Instead of somtimes using an `owner` string to link from a
native handle object to the corresponding JS object, standardize
on a single symbol that fulfills this role.
This makes it easier to provide public APIs in the return types
of `process._getActiveHandles()` and `process._getActiveRequests()`.
@addaleax
Copy link
Member Author

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 29, 2018
@Fishrock123
Copy link
Contributor

This seems like a good idea.

Two questions:

  1. Are we sure we've covered backwards compat enough for now?
  2. Should we deprecate the .owner get/setter, or is that waiting for some other time?

@Fishrock123
Copy link
Contributor

Hmm, on second thought... since this symbol isn't exposed, doesn't this make it difficult to get the owner from a handle as available from an async hook callback?

@AndreasMadsen
Copy link
Member

@Fishrock123 Just want to point out that the resource in async_hooks is not a public API. Especially since running console.log(resource) can crash the application ;)

The API for accessing this information is currently not considered public, but using the Embedder API, users can provide and document their own resource objects.

@Fishrock123
Copy link
Contributor

Just want to point out that the resource in async_hooks is not a public API.

That doesn't make it not a thing to think about.

Especially since running console.log(resource) can crash the application ;)

I can think of lots of ways to crash a node application. Yes, accessing a resource during the init callback specifically is sometimes one of them.

That doesn't mean that people aren't using it, or that it is useful, or that there aren't use-cases we should still keep in mind even for "unofficial" things.

@addaleax
Copy link
Member Author

  1. Are we sure we've covered backwards compat enough for now?

I’m not sure what more to provide than getter/setter pairs for the deprecated properties.

The more breaking-change-y patches will be when we add this symbol to other types of handles.

  1. Should we deprecate the .owner get/setter, or is that waiting for some other time?

No hurry, I’d say.

Hmm, on second thought... since this symbol isn't exposed, doesn't this make it difficult to get the owner from a handle as available from an async hook callback?

@Fishrock123 Would that concern be alleviated once we move async_hooks to also use this symbol for resource objects?

@addaleax
Copy link
Member Author

addaleax commented Aug 1, 2018

@addaleax
Copy link
Member Author

addaleax commented Aug 5, 2018

Landed in af7164e, 5be9b1d

@addaleax addaleax closed this Aug 5, 2018
@addaleax addaleax deleted the async-owner branch August 5, 2018 12:00
addaleax added a commit that referenced this pull request Aug 5, 2018
Instead of somtimes using an `owner` string to link from a
native handle object to the corresponding JS object, standardize
on a single symbol that fulfills this role.

PR-URL: #22002
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
addaleax added a commit that referenced this pull request Aug 5, 2018
This makes it easier to provide public APIs in the return types
of `process._getActiveHandles()` and `process._getActiveRequests()`.

PR-URL: #22002
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
@targos targos added backport-requested-v10.x and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Aug 6, 2018
@targos
Copy link
Member

targos commented Aug 6, 2018

Should this be backported to v10.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

Backport should be relatively easy. There is one more instance of owner_string in src/timer_wrap.cc.

@targos
Copy link
Member

targos commented Aug 19, 2018

Ping @addaleax

addaleax added a commit to addaleax/node that referenced this pull request Aug 24, 2018
Instead of somtimes using an `owner` string to link from a
native handle object to the corresponding JS object, standardize
on a single symbol that fulfills this role.

PR-URL: nodejs#22002
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
addaleax added a commit to addaleax/node that referenced this pull request Aug 24, 2018
This makes it easier to provide public APIs in the return types
of `process._getActiveHandles()` and `process._getActiveRequests()`.

PR-URL: nodejs#22002
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
addaleax added a commit that referenced this pull request Aug 28, 2018
Instead of somtimes using an `owner` string to link from a
native handle object to the corresponding JS object, standardize
on a single symbol that fulfills this role.

PR-URL: #22002
Backport-PR-URL: #22507
Reviewed-By: Michaël Zasso <targos@protonmail.com>
addaleax added a commit that referenced this pull request Aug 28, 2018
This makes it easier to provide public APIs in the return types
of `process._getActiveHandles()` and `process._getActiveRequests()`.

PR-URL: #22002
Backport-PR-URL: #22507
Reviewed-By: Michaël Zasso <targos@protonmail.com>
targos pushed a commit that referenced this pull request Sep 3, 2018
Instead of somtimes using an `owner` string to link from a
native handle object to the corresponding JS object, standardize
on a single symbol that fulfills this role.

PR-URL: #22002
Backport-PR-URL: #22507
Reviewed-By: Michaël Zasso <targos@protonmail.com>
targos pushed a commit that referenced this pull request Sep 3, 2018
This makes it easier to provide public APIs in the return types
of `process._getActiveHandles()` and `process._getActiveRequests()`.

PR-URL: #22002
Backport-PR-URL: #22507
Reviewed-By: Michaël Zasso <targos@protonmail.com>
targos pushed a commit that referenced this pull request Sep 6, 2018
Instead of somtimes using an `owner` string to link from a
native handle object to the corresponding JS object, standardize
on a single symbol that fulfills this role.

PR-URL: #22002
Backport-PR-URL: #22507
Reviewed-By: Michaël Zasso <targos@protonmail.com>
targos pushed a commit that referenced this pull request Sep 6, 2018
This makes it easier to provide public APIs in the return types
of `process._getActiveHandles()` and `process._getActiveRequests()`.

PR-URL: #22002
Backport-PR-URL: #22507
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.