Skip to content
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
cluster: remove deprecated problematic API
Content Warning: mental health and self-harm triggers.

---

The word "suicide" was used in the cluster API 4 years ago.  This was a
serious mistake for several reasons.  It was deprecated in version 6,
and long past time for full removal now.

First, and most important, casual use of words referring to self-harm
serve to stigmatize mental illness and make it harder for people in our
community to literally stay alive.  It is impossible to claim that we
intend to be inclusive and welcoming, and also casually show such
disrespect for the lives of those in our community.  Some of us have
lost friends or struggled with mental illness.  Leaving this lying
around tells us that we are not welcome.

Second, in addition to being just wildly inappropriate on ethical and
community grounds, the term "suicide" was never even appropriate
technically!  In context, it refers to a case where a child process
exits without receiving a fatal signal from the parent process.  The
"cute" unix joke here is that the process "killed itself".  However, the
"suicide" flag is set regardless of how the process exited, so in
addition to being offensive and harmful, it is also misleading and
incorrect, and has always been so.  (It could've thrown an error, called
`process.exit()` or received a fatal signal from some other process.)

An open source project is not the place for emotional landmines.  It's
distracting and misleading at best, and actively harmful at worst.
There is no justification for it.  The API has already been renamed, and
it's an obscure surface that is unlikely to ever be used outside of
core.
  • Loading branch information
isaacs committed Jun 14, 2017
commit 08ebbb31cf57701032ee0111380e588f48922bca
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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