-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Conversation
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.
Nice.
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.
LGTM
I forget if there's a deprecation process for to remove strings from |
@maclover7 |
CHECK(!obj.IsEmpty()); | ||
|
||
v8::TryCatch ignore_exceptions(env->isolate()); | ||
while (true) { |
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 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?
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’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.
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.
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.
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. |
@AndreasMadsen @jasnell I’d really like that (and the fact that |
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()`.
This seems like a good idea. Two questions:
|
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 Just want to point out that the
|
That doesn't make it not a thing to think about.
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. |
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.
No hurry, I’d say.
@Fishrock123 Would that concern be alleviated once we move |
New CI: https://ci.nodejs.org/job/node-test-pull-request/16121/ Edit: Resume CI: https://ci.nodejs.org/job/node-test-pull-request/16127/ Edit: Resume Resume CI: https://ci.nodejs.org/job/node-test-pull-request/16147/ |
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>
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>
Should this be backported to Backport should be relatively easy. There is one more instance of |
Ping @addaleax |
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>
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>
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), orvcbuild test
(Windows) passes