Skip to content

Commit

Permalink
Make parent IPC channel more explicit, describe in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
myndzi committed Sep 8, 2018
1 parent a78ac6b commit 0ddeeb0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ This package came out of frustration with trying to track down the cause of stal
- (10000 ~ 10 s) wrapper @ /home/me/app/node_modules/knex/node_modules/pool2/lib/pool.js:80
- (300000 ~ 5 min) wrapper @ /home/me/app/services/foo.service.js:61

# Note
# Notes

## Timers named "wrapper"
You'll see that the function name listed under timers is `wrapper` -- this is the wrapper around interval timers as created by setInterval. I can still get a source line, but I can't get the original function name out, unfortunately. Caveats like this may exist in other places, too.

## "IPC channel to parent"
When using child_process.fork, or child_process.spawn with default stdio configuration (or possibly when your program is run by something else, such as PM2), an inter-process communication (IPC) channel is opened to send messages between the parent and child. Since this is not based on any code the current program has executed, I can't get much more information than that. It means that the parent end of the connection is still open, so you'll want to investigate whatever spawned the process you're seeing this from.

When using wtfnode from a child process, on version 0.12 there is some strange behavior where a child process handle briefly exists and you will get a warning such as "unable to determine callsite" -- this is peaceful to ignore, and can be avoided by delaying the call to `wtf.dump()` slightly.

# Command line usage

You can install as a global module (`npm install -g wtfnode`) and call a node script manually: `wtfnode <yourscript> <yourargs> ...`
Expand Down
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,20 @@ function dump() {
log('info', '- Others:');
other.forEach(function (o) {
if (!o) { return; }
if (o.constructor) { log('info', ' - %s', o.constructor.name); }
if (isChannel(o)) {
log('info', ' - %s', 'IPC channel to parent (see readme)');
}
else if (o.constructor) { log('info', ' - %s', o.constructor.name); }
else { log('info', ' - %s', o); }
});
}
}
function isChannel(obj) {
// node docs state process.channel added in 7.10, but _channel
// seems to exist prior to that
var ch = process.channel || process._channel;
return ch && obj === ch;
}

function init() {
process.on('SIGINT', function () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wtfnode",
"version": "0.7.0",
"version": "0.7.1",
"description": "Utility to help find out why Node isn't exiting",
"repository": {
"type": "git",
Expand Down
3 changes: 2 additions & 1 deletion test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare -a versions=(
"7"
"8"
"9"
"10"
)

test_version () {
Expand All @@ -29,4 +30,4 @@ for ver in "${versions[@]}"; do
fi
done

nvm use "$CURRENT_VERSION"
nvm use "$CURRENT_VERSION"
4 changes: 3 additions & 1 deletion tests/test-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if (cluster.isMaster) {
var worker = cluster.fork();
worker.on('online', function () {
wtf.dump();
worker.kill();
});
} else {
wtf.dump();
process.exit();
}

0 comments on commit 0ddeeb0

Please sign in to comment.