Skip to content
This repository was archived by the owner on Feb 27, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,10 @@ The `exec`, `env`, `argv`, and `silent` configs are passed to the
* `onMessage` - Method that gets called when workers send a message to
the parent. Called in the context of the worker, so you can reply by
looking at `this`.
* `stopTimeout` - Time in milliseconds to wait for worker to stop before
forcefully killing the process during restart or resize, default 5000
(5 seconds)
* `skepticTimeout` - Time in milliseconds to wait for worker to live
before shutting previous worker down during restart, default 2000
(2 seconds)

9 changes: 7 additions & 2 deletions cluster-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var cluster = require("cluster")
, net = require('net')
, fs = require('fs')
, util = require('util')
, stopTimeout = 5000 // default time (ms) to wait for stop before kill
, skepticTimeout = 2000 // default time (ms) to live before stopping old

exports = module.exports = clusterMaster
exports.restart = restart
Expand Down Expand Up @@ -56,6 +58,9 @@ function clusterMaster (config) {

onmessage = config.onMessage || config.onmessage

if (config.stopTimeout) stopTimeout = config.stopTimeout
if (config.skepticTimeout) skepticTimeout = config.skepticTimeout

clusterSize = config.size || os.cpus().length

env = config.env
Expand Down Expand Up @@ -246,7 +251,7 @@ function forkListener () {
disconnectTimer = setTimeout(function () {
debug("Worker %j, forcefully killing", id)
worker.process.kill("SIGKILL")
}, 5000)
}, stopTimeout)
})
})
}
Expand Down Expand Up @@ -312,7 +317,7 @@ function restart (cb) {
worker.disconnect()
}
graceful()
}, 2000)
}, skepticTimeout)
newbie.on('exit', skeptic)
function skeptic () {
debug('New worker died quickly. Aborting restart.')
Expand Down