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: make getActive{Handles,Requests} official #21102

Closed
wants to merge 1 commit into from
Closed

process: make getActive{Handles,Requests} official #21102

wants to merge 1 commit into from

Conversation

gpotter2
Copy link

@gpotter2 gpotter2 commented Jun 2, 2018

Rebased version of #18844

[Original message]

process._getActiveHandles() and process._getActiveRequests() have been around for a long time, and are utilized to a large enough degree that it makes sense to make them official
APIs.

Fixes: #1128

Checklist :

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines

Affected core subsystem(s)

  • process

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jun 2, 2018
@mscdex
Copy link
Contributor

mscdex commented Jun 2, 2018

If this is going to be a runtime deprecation, you will still need to have the old functions on process, but they will instead throw a proper deprecation error.

@mscdex mscdex added semver-major PRs that contain breaking changes and should be released in the next major version. process Issues and PRs related to the process subsystem. labels Jun 2, 2018
@gpotter2
Copy link
Author

gpotter2 commented Jun 2, 2018

That was already said on the previous thread, I had done it but lost the commit, will search for it.

Edit: is there no travis unit test on node ?

function getActiveTimers() {
const activeHandles = process.getActiveHandles();
return activeHandles.filter((handle) => handle instanceof Timer);
}
Copy link
Member

Choose a reason for hiding this comment

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

It’s hard to tell for me where this function is being used … also, we’re kind of shifting our timers implementation to not use any handles anymore, /cc @apapirovski

Copy link
Author

Choose a reason for hiding this comment

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

Should I remove it ?

@@ -1044,6 +1044,34 @@ a code.
Specifying a code to [`process.exit(code)`][`process.exit()`] will override any
previous setting of `process.exitCode`.

## process.getActiveHandles()
Copy link
Member

Choose a reason for hiding this comment

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

I would really like to take the opportunity now to move these to the async_hooks module or util module and pull them off the process object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Member

Choose a reason for hiding this comment

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

Because I'd prefer not to expand the API surface area of process if we can reasonably avoid it.

Copy link
Contributor

@mscdex mscdex Jun 3, 2018

Choose a reason for hiding this comment

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

It's already there though and people use it. I don't see how it makes more sense to place it on the async_hooks or util modules when the data returned by these functions have to strictly do with what's going on in the process.

async_hooks has to do with hooking into asynchronous events, which is not the same thing as inspecting what is currently happening at any given moment (without hooks).

util is essentially a box full of helper functions that work with whatever input they're given, so that doesn't really fit either.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe you could discuss that in a future PR? I mean, I'm not qualified to answer about this, but I would agree that it's easier to keep the functions where they are.
On the other hand, they were not documented, and could be moved without any further notice

@@ -1005,6 +1005,15 @@ accepted by the legacy `url.parse()` API. The mentioned APIs now use the WHATWG
URL parser that requires strictly valid URLs. Passing an invalid URL is
deprecated and support will be removed in the future.

<a id="DEP0110"></a>
### DEP0110: _getActiveHandles and _getActiveRequests`
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: unnecessary backtick at the end.


Type: Runtime

As `getActiveHandles()` and `getActiveRequests()` are getting officially
Copy link
Contributor

Choose a reason for hiding this comment

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

`process.getActiveHandles()` and `process.getActiveRequests()`?

@@ -1053,6 +1062,8 @@ deprecated and support will be removed in the future.
[`os.networkInterfaces`]: os.html#os_os_networkinterfaces
[`os.tmpdir()`]: os.html#os_os_tmpdir
[`process.env`]: process.html#process_process_env
[`process._getActiveHandles`]: process.html#process_getActiveHandles
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the next links seem unused in the doc.

@vsemozhetbyt vsemozhetbyt added the deprecations Issues and PRs related to deprecations. label Jun 3, 2018

Type: Runtime

As `getActiveHandles()` and `getActiveRequests()` are getting officially
As `process.getActiveHandles()` and `process.getActiveRequests()` are getting officially
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: please wrap long lines at 80 characters to prevent doc linting issues.

Copy link
Author

@gpotter2 gpotter2 Jun 3, 2018

Choose a reason for hiding this comment

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

Fixed ! (also fixed it in lib/bootstrap/node.js)

@vsemozhetbyt
Copy link
Contributor

@gpotter2
Copy link
Author

gpotter2 commented Jun 3, 2018

Update:

  • Fixed the build & linter
  • Squashed commits

@vsemozhetbyt
Copy link
Contributor

@gpotter2
Copy link
Author

gpotter2 commented Jun 3, 2018

I don't really get why the linter fails on using ` for strings, as it is used everywhere else in the file :/

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jun 3, 2018

It seems linter allows backticks only for template strings: with variable/expression interpolation or inner line breaks.

@vsemozhetbyt
Copy link
Contributor

However, you can use double quotes to avoid escaping if the string contains single quotes:

'quotes': ['error', 'single', { avoidEscape: true }],

@gpotter2
Copy link
Author

gpotter2 commented Jun 6, 2018

@vaibhav93 Replaced single quotes with double quotes.

Edit: squashed the commits


Type: Runtime

As `process.getActiveHandles()` and `process.getActiveRequests()` are getting
Copy link
Member

Choose a reason for hiding this comment

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

"are getting" is a bit vague, just say "are."

* Returns: {Array}

Returns an array containing all handles that are preventing the Node.js process
from exiting.
Copy link
Member

Choose a reason for hiding this comment

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

The documentation should make it clear that the returned handles don't always correspond 1-to-1 with user-created handles (only when the internal handle has a .owner property that points back to the user handle but I'd leave out that bit.)

Copy link
Author

Choose a reason for hiding this comment

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

Updated

@gpotter2
Copy link
Author

Rebased against master to fix the conflicts

Make process.getActiveHandles() and make.getActiveRequests() official
and deprecate the older process._getActiveHandles() and
process._getActiveRequests(). Also add a small documentation
@gpotter2
Copy link
Author

Rebased (again) against master to fix conflicts. (wow)

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

IMO these APIs should be rethought a bit before exposure, although exposing something like it officially is pretty much what I'm asking for in #20894 (review) & related comments.

My idea would be more like:

  • Make it part of the async_hooks module for consistency.
  • Rename it to getActiveResources() and return both handles and requests at the same time.
  • Make it return a map of asyncId -> resource, so that this can be used to dynamically fetch a resource from an async hook call.
  • Ensure that all async_hook resources are properly fetch-able in this way.

@AndreasMadsen
Copy link
Member

AndreasMadsen commented Jun 21, 2018

Ensure that all async_hook resources are properly fetch-able in this way.

I agree. But be aware that this is a big task, as many async_hooks resource can have uninitialized properties that causes segmentation fault when using console.log().

edit:

Also, if this is for debugging I would suggest we don't add the extra complexity. As it is straight to implement with async_hooks. Yes there is a performance penalty, but that isn't an issue when debugging. If it is for counting the number of handles, as a performance metric then I would suggest we add an API dedicated to that purpose instead of relying on process._getActiveHandles().length.

The resource objects are very internal and undocumented, I'm not a huge fan of exposing them more than they already are if it can be avoided. This is something I would like to fix in async_hooks too. For example, to expose the public Server object rather than the internal Server handle. I know @addaleax feels the same.

@Fishrock123
Copy link
Contributor

Fishrock123 commented Jun 21, 2018

But be aware that this is a big task, as many async_hooks resource can have uninitialized properties that causes segmentation fault

We've never had such an issue from _getActiveHandles() or _getActiveRequests(). I think that is only an issue within the init hook, and is unrelated to this API.

Also, if this is for debugging

It is not for debugging. In my case it is for live (potentially production) resource inspection. Overhead must be minimal.

we don't add the extra complexity

It's actually very little as most of the complexity already is present in handle_wrap and req_wrap. See #21453 for a mostly complete prototype.

@gpotter2
Copy link
Author

Feel free to close this PR for #21453 anytime

@Fishrock123
Copy link
Contributor

@gpotter2 Thanks for bringing this up. :)

Feel free to add anything you have (use cases, api requirements) in that PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. deprecations Issues and PRs related to deprecations. process Issues and PRs related to the process subsystem. 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.

9 participants