GithubHelp home page GithubHelp logo

keljopap / leaked-handles Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raynos/leaked-handles

0.0 1.0 0.0 231 KB

Detect any handles leaked in node

License: MIT License

JavaScript 100.00%

leaked-handles's Introduction

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.
    debugSockets: true // pretty print tcp thrown exceptions.
});

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

leaked-handles's People

Contributors

raynos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.