Skip to content

Commit

Permalink
test: terminate cluster worker in infinite loop
Browse files Browse the repository at this point in the history
Verify that worker.process.kill() can terminate a cluster worker
stuck in an infinite loop.

PR-URL: #23165
Fixes: #22703
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
cjihrig authored and targos committed Oct 5, 2018
1 parent 5836b9f commit 06b5ef3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/parallel/test-cluster-kill-infinite-loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
const common = require('../common');
const cluster = require('cluster');
const assert = require('assert');

if (cluster.isMaster) {
const worker = cluster.fork();

worker.on('online', common.mustCall(() => {
// Use worker.process.kill() instead of worker.kill() because the latter
// waits for a graceful disconnect, which will never happen.
worker.process.kill();
}));

worker.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGTERM');
}));
} else {
while (true) {}
}

0 comments on commit 06b5ef3

Please sign in to comment.