MCPcopy Index your code
hub / github.com/Raynos/leaked-handles

github.com/Raynos/leaked-handles @v5.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v5.1.0 ↗ · + Follow
17 symbols 49 edges 10 files 0 documented · 0% 3 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

leaked-handles

Detect any handles leaked in node

Example

require("leaked-handles");

Example output.

no of handles 1

timer handle (`setTimeout(any, 1000)`)
timer handle leaked at one of: 
    at Test.t (/home/raynos/uber/leaked-handles/test/leak-timer.js:10:17)
timer listener function any() {}


no of handles 1
tcp handle leaked at one of: 
    at Test.t (/home/raynos/uber/leaked-handles/test/leak-tcp.js:9:22)
tcp stream { fd: 10,
  readable: false,
  writable: true,
  address: { address: '127.0.0.1', family: 'IPv4', port: 39126 } }

Options

require('leaked-handles').set({
    fullStack: true, // use full stack traces
    timeout: 30000 // run every 30 seconds instead of 5.
});

Explanation

Add this to the TOP of your tests as the very first require.

This will now print any handles that keep your process open.

It has pretty printing of some handles including

  • timers. Tells the timeout and the file that leaked it.
  • child processes. Tells you that a handle is leaked because of a spawned child process and the pid.
  • stream. Prints the fact the handle is a stream and the fd.
  • child process stream. Prints the fact the handle is a stream and specifically one of the three fds for the child process.

Debugging tips

When you see a timer, it will print the file, so go fix it!

When you see a child process it prints the pid. Run ps -p {pid} and figure out what kind of child process it is.

When you see a stream it prints the fd. Run lsof -p {process.pid} to see what fds your test process has open and see if you can figure out what the hell it is.

When you see a child process stream, go find the child process that leaked. If no child process leaked then again, use lsof to lookup up the fd.

Installation

npm install leaked-handles

Tests

npm test

Contributors

  • Raynos

MIT Licenced

Core symbols most depended-on inside this repo

printStack
called by 10
print-handles.js
Box
called by 7
stacks.js
printHandles
called by 7
print-handles.js
FakeLogger
called by 5
test/lib/fake-logger.js
printStream
called by 3
print-handles.js
applyKeyedList
called by 2
stacks.js
printTimer
called by 2
print-handles.js
stackLineType
called by 1
print-handles.js

Shape

Function 17

Languages

TypeScript100%

Modules by API surface

print-handles.js13 symbols
stacks.js3 symbols
test/lib/fake-logger.js1 symbols

Used by 3 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add leaked-handles \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact