Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,33 @@ a code.
Specifying a code to [`process.exit(code)`][`process.exit()`] will override any
previous setting of `process.exitCode`.

## process.getActiveHandles()
<!-- YAML
added: REPLACEME
-->

* Returns: {Array}

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

```js
console.log(`Active handles: ${util.inspect(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.

More information about the things that are in the array would be helpful. What kind of objects are they? What can the user basically do with them, ec

Copy link
Member

Choose a reason for hiding this comment

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

+1, util.inspecting them and then console.loging does not seem to be a good example since console.log will util.inspect them anyway..

Copy link

@ShanMadane ShanMadane Jan 28, 2020

Choose a reason for hiding this comment

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

I would like to know which active handles are open for a particular process id. How can I get it


## process.getActiveRequests()
<!-- YAML
added: REPLACEME
-->

* Returns: {Array}

Returns an array containing all requests that are preventing the Node.js process
from exiting.

```js
console.log(`Active requests: ${util.inspect(process.getActiveRequests())}`);
```

## process.getegid()
<!-- YAML
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@

function setupProcessObject() {
process._setupProcessObject(pushValueToArray);
process._getActiveHandles = process.getActiveHandles;
process._getActiveRequests = process.getActiveRequests;
Copy link
Member

Choose a reason for hiding this comment

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

Should this include some form of deprecation for the _-prefixed versions?


function pushValueToArray() {
for (var i = 0; i < arguments.length; i++)
Expand Down
4 changes: 2 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3195,8 +3195,8 @@ void SetupProcessObject(Environment* env,
env->SetMethod(process,
"_stopProfilerIdleNotifier",
StopProfilerIdleNotifier);
env->SetMethod(process, "_getActiveRequests", GetActiveRequests);
env->SetMethod(process, "_getActiveHandles", GetActiveHandles);
env->SetMethod(process, "getActiveRequests", GetActiveRequests);
env->SetMethod(process, "getActiveHandles", GetActiveHandles);
env->SetMethod(process, "reallyExit", Exit);
env->SetMethod(process, "abort", Abort);
env->SetMethod(process, "chdir", Chdir);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-process-getactivehandles.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function clientConnected(client) {


function checkAll() {
const handles = process._getActiveHandles();
const handles = process.getActiveHandles();

clients.forEach(function(item) {
assert.ok(handles.includes(item));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ const handle1 = setTimeout(common.mustCall(function() {
}), TIMEOUT);

function getActiveTimers() {
const activeHandles = process._getActiveHandles();
const activeHandles = process.getActiveHandles();
return activeHandles.filter((handle) => handle instanceof Timer);
}
2 changes: 1 addition & 1 deletion test/pseudo-tty/ref_keeps_node_running.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ handle.readStart();
handle.onread = () => {};

function isHandleActive(handle) {
return process._getActiveHandles().some((active) => active === handle);
return process.getActiveHandles().some((active) => active === handle);
}

strictEqual(isHandleActive(handle), true, 'TTY handle not initially active');
Expand Down
4 changes: 2 additions & 2 deletions test/pummel/test-net-connect-econnrefused.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function pummel() {

function check() {
setTimeout(function() {
assert.strictEqual(process._getActiveRequests().length, 0);
assert.strictEqual(process._getActiveHandles().length, 1); // the timer
assert.strictEqual(process.getActiveRequests().length, 0);
assert.strictEqual(process.getActiveHandles().length, 1); // the timer
check_called = true;
}, 0);
}
Expand Down