From 0e763d921bf4e2ad6d044c6e19931c791da8f6f1 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 15 Jun 2017 08:22:07 -0700 Subject: [PATCH 1/3] doc: EOL deprecated API and update notes --- doc/api/deprecations.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index d06e70a10c9e30..63c529bc653ae1 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -95,12 +95,16 @@ methods, the `options.customFds` option is deprecated. The `options.stdio` option should be used instead. -### DEP0007: cluster worker.suicide +### DEP0007: Replace cluster worker.suicide with worker.exitedAfterDisconnect -Type: Runtime +Type: End-of-Life -Within the `cluster` module, the [`worker.suicide`][] property has been -deprecated. Please use [`worker.exitedAfterDisconnect`][] instead. +In an earlier version of the Node.js `cluster`, a boolean property with the name +`suicide` was added to the `Worker` object. The intent of this property was to +provide an indication of how and why the `Worker` instance exited. In Node.js +6.0.0, the old property was deprecated and replaced with a new +[worker.exitedAfterDisconnect][] property. The old property name did not +precisely describe the actual semantics and was unnecessarily emotion-laden. ### DEP0008: require('constants') @@ -689,7 +693,6 @@ Type: Runtime [`util.puts()`]: util.html#util_util_puts_strings [`util`]: util.html [`worker.exitedAfterDisconnect`]: cluster.html#cluster_worker_exitedafterdisconnect -[`worker.suicide`]: cluster.html#cluster_worker_suicide [alloc]: buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding [alloc_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size [from_arraybuffer]: buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length From 193b0da4931c7ae046ade2b19228749531cdbb79 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 15 Jun 2017 08:30:20 -0700 Subject: [PATCH 2/3] test: use worker.exitedAfterDisconnect consistently --- .../test-cluster-worker-constructor.js | 4 ++-- .../parallel/test-cluster-worker-deprecated.js | 18 ------------------ .../parallel/test-cluster-worker-disconnect.js | 4 ---- test/parallel/test-cluster-worker-exit.js | 2 -- test/parallel/test-regress-GH-3238.js | 4 ++-- 5 files changed, 4 insertions(+), 28 deletions(-) delete mode 100644 test/parallel/test-cluster-worker-deprecated.js diff --git a/test/parallel/test-cluster-worker-constructor.js b/test/parallel/test-cluster-worker-constructor.js index a8094e34df9c72..06a1ad774ccc51 100644 --- a/test/parallel/test-cluster-worker-constructor.js +++ b/test/parallel/test-cluster-worker-constructor.js @@ -29,7 +29,7 @@ const cluster = require('cluster'); let worker; worker = new cluster.Worker(); -assert.strictEqual(worker.suicide, undefined); +assert.strictEqual(worker.exitedAfterDisconnect, undefined); assert.strictEqual(worker.state, 'none'); assert.strictEqual(worker.id, 0); assert.strictEqual(worker.process, undefined); @@ -39,7 +39,7 @@ worker = new cluster.Worker({ state: 'online', process: process }); -assert.strictEqual(worker.suicide, undefined); +assert.strictEqual(worker.exitedAfterDisconnect, undefined); assert.strictEqual(worker.state, 'online'); assert.strictEqual(worker.id, 3); assert.strictEqual(worker.process, process); diff --git a/test/parallel/test-cluster-worker-deprecated.js b/test/parallel/test-cluster-worker-deprecated.js deleted file mode 100644 index 2f433aae797ccc..00000000000000 --- a/test/parallel/test-cluster-worker-deprecated.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; -require('../common'); - -const assert = require('assert'); -const cluster = require('cluster'); - -const worker = new cluster.Worker(); - -assert.strictEqual(worker.exitedAfterDisconnect, undefined); -assert.strictEqual(worker.suicide, undefined); - -worker.exitedAfterDisconnect = 'recommended'; -assert.strictEqual(worker.exitedAfterDisconnect, 'recommended'); -assert.strictEqual(worker.suicide, 'recommended'); - -worker.suicide = 'deprecated'; -assert.strictEqual(worker.exitedAfterDisconnect, 'deprecated'); -assert.strictEqual(worker.suicide, 'deprecated'); diff --git a/test/parallel/test-cluster-worker-disconnect.js b/test/parallel/test-cluster-worker-disconnect.js index 0554671fea3b61..1c5a7fc3ae51f9 100644 --- a/test/parallel/test-cluster-worker-disconnect.js +++ b/test/parallel/test-cluster-worker-disconnect.js @@ -29,12 +29,8 @@ if (cluster.isWorker) { http.Server(() => { }).listen(0, '127.0.0.1'); - const worker = cluster.worker; - assert.strictEqual(worker.exitedAfterDisconnect, worker.suicide); cluster.worker.on('disconnect', common.mustCall(() => { - assert.strictEqual(cluster.worker.exitedAfterDisconnect, - cluster.worker.suicide); process.exit(42); })); diff --git a/test/parallel/test-cluster-worker-exit.js b/test/parallel/test-cluster-worker-exit.js index 75a271278f6d30..ba9c4f8775760e 100644 --- a/test/parallel/test-cluster-worker-exit.js +++ b/test/parallel/test-cluster-worker-exit.js @@ -52,7 +52,6 @@ if (cluster.isWorker) { worker_emitDisconnect: [1, "the worker did not emit 'disconnect'"], worker_emitExit: [1, "the worker did not emit 'exit'"], worker_state: ['disconnected', 'the worker state is incorrect'], - worker_suicideMode: [false, 'the worker.suicide flag is incorrect'], worker_exitedAfterDisconnect: [ false, 'the .exitedAfterDisconnect flag is incorrect' ], @@ -84,7 +83,6 @@ if (cluster.isWorker) { // Check worker events and properties worker.on('disconnect', common.mustCall(() => { results.worker_emitDisconnect += 1; - results.worker_suicideMode = worker.suicide; results.worker_exitedAfterDisconnect = worker.exitedAfterDisconnect; results.worker_state = worker.state; if (results.worker_emitExit > 0) { diff --git a/test/parallel/test-regress-GH-3238.js b/test/parallel/test-regress-GH-3238.js index e6fe030bda9a10..dd65d849d57503 100644 --- a/test/parallel/test-regress-GH-3238.js +++ b/test/parallel/test-regress-GH-3238.js @@ -7,11 +7,11 @@ if (cluster.isMaster) { function forkWorker(action) { const worker = cluster.fork({ action }); worker.on('disconnect', common.mustCall(() => { - assert.strictEqual(worker.suicide, true); + assert.strictEqual(worker.exitedAfterDisconnect, true); })); worker.on('exit', common.mustCall(() => { - assert.strictEqual(worker.suicide, true); + assert.strictEqual(worker.exitedAfterDisconnect, true); })); } From 6f73f4fba3447d446150129eda5527319e9726b7 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 15 Jun 2017 08:52:52 -0700 Subject: [PATCH 3/3] cluster: make deprecated property non-enumerable Make deprecated property non-enumerable, remove from docs --- doc/api/cluster.md | 34 ---------------------------------- lib/internal/cluster/worker.js | 9 ++++----- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/doc/api/cluster.md b/doc/api/cluster.md index c7d8359ac0ce93..721b33a7e184f1 100644 --- a/doc/api/cluster.md +++ b/doc/api/cluster.md @@ -451,40 +451,6 @@ if (cluster.isMaster) { } ``` -### worker.suicide - - -> Stability: 0 - Deprecated: Use [`worker.exitedAfterDisconnect`][] instead. - -An alias to [`worker.exitedAfterDisconnect`][]. - -Set by calling `.kill()` or `.disconnect()`. Until then, it is `undefined`. - -The boolean `worker.suicide` is used to distinguish between voluntary -and accidental exit, the master may choose not to respawn a worker based on -this value. - -```js -cluster.on('exit', (worker, code, signal) => { - if (worker.suicide === true) { - console.log('Oh, it was just voluntary – no need to worry'); - } -}); - -// kill worker -worker.kill(); -``` - -This API only exists for backwards compatibility and will be removed in the -future. - ## Event: 'disconnect'