Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
why-is-node-running
Advanced tools
Node is running but you don't know why? why-is-node-running is here to help you.
The why-is-node-running package is a Node.js module that helps developers diagnose why a Node.js process hasn't exited on its own. It provides insights into what operations are keeping the event loop busy, such as open handles, active timers, and other system tasks that may prevent the process from exiting.
Logging active handles
This feature allows you to log all active handles that are currently preventing Node.js from exiting. It's useful for identifying potential sources of memory leaks or unintended behavior.
const log = require('why-is-node-running');
// somewhere in your long-running program
log(); // logs out active handles that are keeping node running
Logging with a delay
This feature is similar to the previous one, but it allows you to set a delay before logging the active handles. This can be useful when you want to give your application some time to settle before checking what is still running.
const log = require('why-is-node-running');
setTimeout(function () {
log(); // logs out active handles after a delay
}, 10000);
WTFNode is similar to why-is-node-running in that it helps to diagnose what is keeping a Node.js process running. It provides detailed output about timers, sockets, and other resources. It differs in its output format and the level of detail provided.
Node-report is an npm package that provides a diagnostic report on demand or when certain events occur. It's more comprehensive than why-is-node-running, offering information about the system, resource usage, and JavaScript stack trace, but it's not as focused on the reasons why a Node.js process is still running.
Node is running but you don't know why? why-is-node-running
is here to help you.
Node 8 and above:
npm i why-is-node-running -g
Earlier Node versions (no longer supported):
npm i why-is-node-running@v1.x -g
const log = require('why-is-node-running') // should be your first require
const net = require('net')
function createServer () {
const server = net.createServer()
setInterval(function () {}, 1000)
server.listen(0)
}
createServer()
createServer()
setTimeout(function () {
log() // logs out active handles that are keeping node running
}, 100)
Save the file as example.js
, then execute:
node ./example.js
Here's the output:
There are 5 handle(s) keeping the process running
# Timeout
/home/maf/dev/node_modules/why-is-node-running/example.js:6 - setInterval(function () {}, 1000)
/home/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
# TCPSERVERWRAP
/home/maf/dev/node_modules/why-is-node-running/example.js:7 - server.listen(0)
/home/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
# Timeout
/home/maf/dev/node_modules/why-is-node-running/example.js:6 - setInterval(function () {}, 1000)
/home/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()
# TCPSERVERWRAP
/home/maf/dev/node_modules/why-is-node-running/example.js:7 - server.listen(0)
/home/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()
# Timeout
/home/maf/dev/node_modules/why-is-node-running/example.js:13 - setTimeout(function () {
You can also run why-is-node-running
as a standalone if you don't want to include it inside your code. Sending SIGUSR1
signal to the process will produce the log.
why-is-node-running /path/to/some/file.js
probing module /path/to/some/file.js
kill -SIGUSR1 31115 for logging
To trigger the log:
kill -SIGUSR1 31115
MIT
FAQs
Node is running but you don't know why? why-is-node-running is here to help you.
We found that why-is-node-running demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.