From 8e7df048a7f5e69c5716fe03ed059f3cec768bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Tue, 25 Jan 2022 20:36:51 +0100 Subject: [PATCH] doc: remove unadvisable cluster example 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: https://github.com/nodejs/node/commit/5f08c3cfa1ee3ece6032d1ffeda6f403e54dd5c0 PR-URL: https://github.com/nodejs/node/pull/41668 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Rich Trott Reviewed-By: Mestery Reviewed-By: Colin Ihrig Reviewed-By: Tierney Cyren --- doc/api/cluster.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/doc/api/cluster.md b/doc/api/cluster.md index 10af5fa20a1e03..c655305b4c25a8 100644 --- a/doc/api/cluster.md +++ b/doc/api/cluster.md @@ -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