Skip to content

Instantly share code, notes, and snippets.

@Raynos
Last active August 29, 2015 14:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/df7a19a30faa917671d3 to your computer and use it in GitHub Desktop.
Save Raynos/df7a19a30faa917671d3 to your computer and use it in GitHub Desktop.
What keeps my process open?
var setInterval = require('timers').setInterval;
setInterval(function () {
var handles = process._getActiveHandles();
console.log('no of handles', handles.length);
handles.forEach(function (obj) {
if ('ontimeout' in obj) {
console.log('timer handle', obj);
} else if ('readable' in obj && 'writable' in obj) {
// to debug stream handles print the _events functions
// to string and figure out what kind of stream they are
// then stare really hard at the source code
// console.log(obj._events.end.toString());
console.log('stream handle', obj);
} else {
console.log('unknown handle', obj);
}
})
}, 5000).unref();
@othiym23
Copy link

That seems pretty good, but it won't catch any inflight libuv requests (process._getActiveRequests()). But that's even harder to reason about than the handle list. I generally just hand-code a filter like yours and narrow it down until it excludes all the handles I'm expecting, and then dump the rest and start digging from there.

@bnoordhuis
Copy link

obj.owner is the owning "public" object, e.g. the encapsulating net.Socket for a TCP handle.

Doesn't work for regular timers because they sit in a queue backed by a single timer handle but it does work for timers that have been unref()'d; those get moved out of the queue and assigned individual timer handles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment