Skip to content

Instantly share code, notes, and snippets.

@Raynos Raynos/open-handles.js
Last active Aug 29, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Jun 23, 2014

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

This comment has been minimized.

Copy link

commented Jun 23, 2014

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
You can’t perform that action at this time.