Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: update deprecated API #13704

Closed
wants to merge 3 commits into from
Closed
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
34 changes: 0 additions & 34 deletions doc/api/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,40 +451,6 @@ if (cluster.isMaster) {
}
```

### worker.suicide
<!-- YAML
added: v0.7.0
deprecated: v6.0.0
changes:
- version: v7.0.0
pr-url: https://github.com/nodejs/node/pull/3747
description: Accessing this property will now emit a deprecation warning.
-->

> 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'
<!-- YAML
added: v0.7.9
Expand Down
13 changes: 8 additions & 5 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ methods, the `options.customFds` option is deprecated. The `options.stdio`
option should be used instead.

<a id="DEP0007"></a>
### DEP0007: cluster worker.suicide
### DEP0007: Replace cluster worker.suicide with worker.exitedAfterDisconnect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider removing the phrase from the error code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I think it's necessary for context, otherwise those seeing the deprecation error and not having any context won't really have a clue what it is about, or any ability to find out. The whole reason deprecations.md exists is to provide that context when necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be a reference though right? like give you a url to check the extended documentation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the extended documentation. This message is in deprecations.md, this is not the warning message that is printed to the console.


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.

<a id="DEP0008"></a>
### DEP0008: require('constants')
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions lib/internal/cluster/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const EventEmitter = require('events');
const internalUtil = require('internal/util');
const util = require('util');
const defineProperty = Object.defineProperty;
const suicideDeprecationMessage =
'worker.suicide is deprecated. Please use worker.exitedAfterDisconnect.';
const deprecationMessage = 'Please use worker.exitedAfterDisconnect.';

module.exports = Worker;

Expand All @@ -23,11 +22,11 @@ function Worker(options) {
defineProperty(this, 'suicide', {
get: internalUtil.deprecate(
() => this.exitedAfterDisconnect,
suicideDeprecationMessage, 'DEP0007'),
deprecationMessage, 'DEP0007'),
set: internalUtil.deprecate(
(val) => { this.exitedAfterDisconnect = val; },
suicideDeprecationMessage, 'DEP0007'),
enumerable: true
deprecationMessage, 'DEP0007'),
enumerable: false
});

this.state = options.state || 'none';
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-cluster-worker-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
18 changes: 0 additions & 18 deletions test/parallel/test-cluster-worker-deprecated.js

This file was deleted.

4 changes: 0 additions & 4 deletions test/parallel/test-cluster-worker-disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));

Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-cluster-worker-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-regress-GH-3238.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
}

Expand Down