Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Forkie is a graceful process manager which allows you to:
Forkie solves the "how do we deal with graceful start an stops in our node.js application?".
See the examples.
A forkie master will forks all the workers you give to him. Workers must implement the worker API.
var workers = [
'job-worker.js',
'job-worker2.js',
'job-worker2.js',
require('cluster'),
require('cluster')
];
// default options
var opts = {
start: process.nextTick, // executes before starting processes
stop: process.nextTick, // executes before stopping processes
killTimeout: 5000 // how much `ms` to wait before killing a process that does not exits by itself
restarts: false // how many times should we restart a failed process, put `Infinity` or -1 for infinite restarts
repl: false // should we start a repl? See repl documentation
};
var master = require('forkie').master(workers, opts);
master.on('worker stopped', function(metas) {
console.log(metas.title); // worker title, see worker API
console.log(metas.code) // exit code
console.log(metas.signal) // exit signal, should be SIGKILL when killTimeout occurs
});
// on ready and started events, you get the `{ title: 'worker title' }`
master.on('worker ready', console.log);
master.on('worker started', console.log);
// this will be called before
// starting workers
function startMaster(cb) {
setTimeout(cb, 3000);
}
// this will be called before
// stopping workers
function stopMaster(cb) {
setTimeout(cb, 1500);
}
Forkie can provide you a handy REPL to start/stop/restart workers individually.
You can use all the options from dshaw/replify.
See the many usable clients on to connect to the REPL.
Here's an example from examples/master-repl.js using dshaw/repl-client:
The worker API can be used in conjunction with a master process (master-worker) or as a standalone worker.
var title = 'I am a worker';
var opts = {
start: startWorker,
stop: stopWorker
};
var worker = require('forkie').worker(title, opts);
worker.on('stopped', console.log);
worker.on('started', console.log);
worker.on('ready', console.log);
function startWorker(cb) {
setTimeout(cb, 3000);
}
function stopWorker(cb) {
setTimeout(cb, 1500);
}
By default, as soon as master receives a SIGTERM or SIGINT, all workers are asked to stop.
To inform forkie that you are dealing with long asynchronous tasks
and that you don't want to be interrupted, use worker.working(true)
.
For example, when using a work queue,
before starting to work on a job, use worker.working(true)
,
after dealing with a job, use worker.working(false)
.
See examples/job-worker.js for a more concrete example.
All messages are sent with IPC
start(cb)
function{ graceful: { status: 'ready' } }
message, received by master{ graceful: { action: 'start' } }
, received by workersstart(cb)
function{ graceful: { status: 'started' } }
, received by master{ graceful: { status: 'started' } }
eventSIGTERM
stop(cb)
function{ graceful: { action: 'stop' } }
, received by workersstop(cb)
function{ graceful: { status: 'stopped' } }
, received by master{ graceful: { status: 'stopped' } }
eventIf worker was working (i.e. .working(true)
was called last), it will wait
for .working(false)
to be called.
If worker did not gracefully exits before killTimeout
, it will be .kill('SIGKILL')ed.
If master does not exits by itself, it will stay online.
Master and worker exits are up to you, you must close all connections and timers for process to exits gracefully.
When master fails, all forked workers will automatically exit because they listen to disconnect event.
Forkie will not call process.exit()
for you.
All you workers must terminate their respective
connections and async loops in the stop
method.
So that your process exits by itself.
When in a master-worker setup, your worker will be killed
after killTimeout
ms if it doesn't exits.
When in a standalone worker setup, your worker will not exits if you don't terminate your connections.
FAQs
forkie likes your forks
We found that forkie demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.