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: remove deprecated problematic API #13684

Closed
wants to merge 1 commit 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
10 changes: 0 additions & 10 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ Within the [`child_process`][] module's `spawn()`, `fork()`, and `exec()`
methods, the `options.customFds` option is deprecated. The `options.stdio`
option should be used instead.

<a id="DEP0007"></a>
### DEP0007: cluster worker.suicide
Copy link
Member

Choose a reason for hiding this comment

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

-1 on this bit. Per the deprecation policy, the deprecation code is static and permanent and should remain in the documentation. The Type: line should be changed to End-of-Life`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's more or less policy I think to leave the code?

Maybe we can just say "the predecessor to cluster worker.exitedAfterDisconnect"?

Copy link
Member

Choose a reason for hiding this comment

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

That works for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

-1 on using roundabout wording. We can't remove problematic terminology from everywhere (for example, git history). deprecations.md is a file that has a very specific purpose, and most people will never look at it.

Example: someone is trying to resurrect some old code that no longer works due to a call to a non-existent method. Searching for it in deprecations.md would probably be the first step. If the section about a removed API doesn't name the API, then there's no point in having it at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, your probably right about that, unfortunately.


Type: Runtime

Within the `cluster` module, the [`worker.suicide`][] property has been
deprecated. Please use [`worker.exitedAfterDisconnect`][] instead.
Copy link
Member

Choose a reason for hiding this comment

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

What I would recommend here is adding a short, non-emotional explanation why worker.suicide was renamed/removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we at least add a content warning at the top of the file, that this document contains offensive and triggering language?


<a id="DEP0008"></a>
### DEP0008: require('constants')

Expand Down Expand Up @@ -688,8 +680,6 @@ Type: Runtime
[`util.print()`]: util.html#util_util_print_strings
[`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
14 changes: 0 additions & 14 deletions lib/internal/cluster/worker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict';
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.';

module.exports = Worker;

Expand All @@ -20,16 +16,6 @@ function Worker(options) {

this.exitedAfterDisconnect = undefined;

defineProperty(this, 'suicide', {
get: internalUtil.deprecate(
() => this.exitedAfterDisconnect,
suicideDeprecationMessage, 'DEP0007'),
set: internalUtil.deprecate(
(val) => { this.exitedAfterDisconnect = val; },
suicideDeprecationMessage, 'DEP0007'),
enumerable: true
});

this.state = options.state || 'none';
this.id = options.id | 0;

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
8 changes: 4 additions & 4 deletions test/parallel/test-cluster-worker-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const cluster = require('cluster');
const worker = new cluster.Worker();

assert.strictEqual(worker.exitedAfterDisconnect, undefined);
assert.strictEqual(worker.suicide, undefined);
assert.strictEqual(worker.exitedAfterDisconnect, undefined);
Copy link
Member

Choose a reason for hiding this comment

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

Can this test just be removed? AIUI from 3f61521 this is just to test that the deprecated properties work properly, and we're removing them.

cc/ @Trott

Copy link
Member

Choose a reason for hiding this comment

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

@gibfahn Yes, I agree, it seems like this test file can be removed rather than modified.


worker.exitedAfterDisconnect = 'recommended';
assert.strictEqual(worker.exitedAfterDisconnect, 'recommended');
assert.strictEqual(worker.suicide, 'recommended');
assert.strictEqual(worker.exitedAfterDisconnect, 'recommended');

worker.suicide = 'deprecated';
worker.exitedAfterDisconnect = 'deprecated';
assert.strictEqual(worker.exitedAfterDisconnect, 'deprecated');
assert.strictEqual(worker.exitedAfterDisconnect, 'deprecated');
assert.strictEqual(worker.suicide, 'deprecated');
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'],
Copy link
Contributor

Choose a reason for hiding this comment

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

just to confirm, this mode was only entered when using the deprecated API correct?

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