Skip to content

Commit

Permalink
doc: remove unadvisable cluster example
Browse files Browse the repository at this point in the history
Applications should usually keep track of workers themselves to prevent
cross-referencing workers from different "groups" that are assigned to
separate tasks.

Additionally, it is unreasonable to assume that the 'data' event emitted
by a socket object will be an integer. While the example works when the
argument is a string (or Buffer), it can result in various issues (e.g.,
when id === '__proto__' since cluster.workers has a non-null prototype).

Refs: 5f08c3c

PR-URL: #41668
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Mestery <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tierney Cyren <[email protected]>
  • Loading branch information
tniessen authored and ruyadorno committed Feb 7, 2022
1 parent 0ee468d commit 8e7df04
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions doc/api/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -1087,14 +1087,6 @@ for (const worker of Object.values(cluster.workers)) {
}
```

Using the worker's unique id is the easiest way to locate the worker.

```js
socket.on('data', (id) => {
const worker = cluster.workers[id];
});
```

[Advanced serialization for `child_process`]: child_process.md#advanced-serialization
[Child Process module]: child_process.md#child_processforkmodulepath-args-options
[`.fork()`]: #clusterforkenv
Expand Down

0 comments on commit 8e7df04

Please sign in to comment.