Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rcoedo/52856b224497304cc7bd95d7903100f7 to your computer and use it in GitHub Desktop.
Save rcoedo/52856b224497304cc7bd95d7903100f7 to your computer and use it in GitHub Desktop.
This gist contains the examples for the article "Detecting Node.js Active Handles with wtfnode".
- https://medium.com/trabe/detecting-node-js-active-handles-with-wtfnode-704e91f2b120
- https://rcoedo.com/blog/2019/08/12/detecting-node-js-active-handles-with-wtfnode
-------------------
handles: [ WriteStream {
connecting: false,
_hadError: false,
_handle:
TTY {
onread: [Function: onStreamRead],
[Symbol(owner)]: [Circular] },
_parent: null,
_host: null,
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
emitClose: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: false,
_events: { end: [Function: onReadableStreamEnd] },
_eventsCount: 1,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 5,
prefinished: false,
errorEmitted: false,
emitClose: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
columns: 158,
rows: 44,
_type: 'tty',
fd: 1,
_isStdio: true,
destroySoon: [Function: destroy],
_destroy: [Function],
[Symbol(asyncId)]: 2,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0 },
WriteStream {
connecting: false,
_hadError: false,
_handle:
TTY {
onread: [Function: onStreamRead],
[Symbol(owner)]: [Circular] },
_parent: null,
_host: null,
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
emitClose: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: false,
_events: { end: [Function: onReadableStreamEnd] },
_eventsCount: 1,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
columns: 158,
rows: 44,
_type: 'tty',
fd: 2,
_isStdio: true,
destroySoon: [Function: destroy],
_destroy: [Function],
[Symbol(asyncId)]: 4,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0 },
Timer {
_list:
TimersList {
_idleNext: [Timeout],
_idlePrev: [Timeout],
_unrefed: false,
msecs: 1000,
_timer: [Circular] } } ]
requests: []
-------------------
setTimeout(() => {
console.log("Look mom, I'm inside a timeout!");
}, 1000);
console.log("-------------------");
console.log("handles:", process._getActiveHandles());
console.log("requests:", process._getActiveRequests());
console.log("-------------------\n");
static int uv__loop_alive(const uv_loop_t* loop) {
return uv__has_active_handles(loop) ||
uv__has_active_reqs(loop) ||
loop->closing_handles != NULL;
}
const wtf = require("wtfnode");
console.log("First dump");
console.log("-------------------");
wtf.dump();
console.log("-------------------\n");
setTimeout(() => {
console.log("Look mom, I'm inside a timeout!");
}, 1000);
console.log("Second dump");
console.log("-------------------");
wtf.dump();
console.log("-------------------\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment