-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cluster: send suicide message on disconnect
This commit causes Worker.prototype.disconnect() to send a suicide message to the cluster master. The function is also restructured to eliminate redundant code. Fixes: #3238 PR-URL: #3720 Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
9ef81ff
commit 47f3735
Showing
2 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cluster = require('cluster'); | ||
|
||
if (cluster.isMaster) { | ||
const worker = cluster.fork(); | ||
let disconnected = false; | ||
|
||
worker.on('disconnect', common.mustCall(function() { | ||
assert.strictEqual(worker.suicide, true); | ||
disconnected = true; | ||
})); | ||
|
||
worker.on('exit', common.mustCall(function() { | ||
assert.strictEqual(worker.suicide, true); | ||
assert.strictEqual(disconnected, true); | ||
})); | ||
} else { | ||
cluster.worker.disconnect(); | ||
} |