summaryrefslogtreecommitdiff
path: root/lib/cluster.js
AgeCommit message (Collapse)Author
2017-07-07lib: use consistent indentation for ternariesRich Trott
In anticipation of stricter linting for indentation issues, modify ternary operators in lib that do not conform with the expected ESLint settings. PR-URL: https://github.com/nodejs/node/pull/14078 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-03-10meta: restore original copyright headerJames M Snell
A prior io.js era commit inappropriately removed the original copyright statements from the source. This restores those in any files still remaining from that edit. Ref: https://github.com/nodejs/TSC/issues/174 Ref: https://github.com/nodejs/node/pull/10599 PR-URL: https://github.com/nodejs/node/pull/10155 Note: This PR was required, reviewed-by and approved by the Node.js Foundation Legal Committee and the TSC. There is no `Approved-By:` meta data.
2017-01-13cluster: refactor module into multiple filescjihrig
This commit splits the existing cluster module into several internal modules. More specifically, the cluster master and worker implementations are separated, and the various data structures are separated. PR-URL: https://github.com/nodejs/node/pull/10746 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2017-01-09test,cluster: add test-cluster-worker-deprecatedRich Trott
Add test to cover setter for deprecated cluster Worker property. Previously, the setter was not being exercised in tests. PR-URL: https://github.com/nodejs/node/pull/10675 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2016-12-19cluster: return worker reference from disconnect()Sean Villars
Changes disconnect() to return a refererence to the worker. This will enable method chaining such as worker.disconnect().once('disconnect', doThis); PR-URL: https://github.com/nodejs/node/pull/10019 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2016-10-03cluster: remove unused backlog argumentBrian White
PR-URL: https://github.com/nodejs/node/pull/8877 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2016-08-01cluster: support stdio option for workerscjihrig
This commit allows setupMaster() to configure the stdio channels for worker processes. Refs: https://github.com/nodejs/node-v0.x-archive/issues/5727 Refs: https://github.com/nodejs/node/pull/7811 PR-URL: https://github.com/nodejs/node/pull/7838 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-07-15cluster: remove bind() and selfcjihrig
This commit removes the use of self and bind() from the cluster module in favor of arrow functions. PR-URL: https://github.com/nodejs/node/pull/7710 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
2016-06-08cluster: don't send messages if no IPC channelSantiago Gimeno
Avoid sending messages if the IPC channel is already disconnected. It avoids undesired errors when calling `process.disconnect` when there are still pending IPC messages. PR-URL: https://github.com/nodejs/node/pull/7132 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-06-05cluster: deprecate worker.suicideEvan Lucas
Deprecate worker.suicide in favor of worker.exitedAfterDisconnect. PR-URL: https://github.com/nodejs/node/pull/3747 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2016-05-31cluster: expose result of send()cjihrig
There are several places in the cluster module where a version of process.send() is called, but the result is swallowed. Most of these cases are internal, but Worker.prototype.send(), which is publicly documented, also suffers from this problem. This commit exposes the return value to facilitate better error handling, and bring Worker.prototype.send() into compliance with the documentation. PR-URL: https://github.com/nodejs/node/pull/6998 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-05-31cluster: rewrite debug ports consistentlycjihrig
When debug flags are passed to clustered applications, the debug port is rewritten for each worker process to avoid collisions. Prior to this commit, each debug flag would get a unique value. This commit reworks the logic to assign the same port value to all debug flags for a single worker. PR-URL: https://github.com/nodejs/node/pull/7050 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2016-05-30cluster: work with v8_inspectorcjihrig
PR-URL: https://github.com/nodejs/node/pull/6792 Reviewed-By: jasnell - James M Snell <jasnell@gmail.com> Reviewed-By: addaleax - Anna Henningsen <anna@addaleax.net> Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
2016-05-27cluster: reset handle index on closeSantiago Gimeno
It allows reopening a server after it has been closed. Fixes: https://github.com/nodejs/node/issues/6693 PR-URL: https://github.com/nodejs/node/pull/6981 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-05-25cluster: guard against undefined message handlerscjihrig
cluster's internal message handling includes a cache of callback functions. Once the message for that callback is received, it is removed from the cache. If, for any reason, the same message ID is processed twice, the callback will be missing from the cache and cluster will try to call undefined as a function. This commit guards against this scenario. Refs: https://github.com/nodejs/node/issues/6561 PR-URL: https://github.com/nodejs/node/pull/6902 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2016-05-24cluster: close ownerless handles on disconnect()cjihrig
When a worker is disconnecting, it shuts down all of the handles it is waiting on. It is possible that a handle does not have an owner, which causes a crash. This commit closes such handles without accessing the missing owner. Fixes: https://github.com/nodejs/node/issues/6561 PR-URL: https://github.com/nodejs/node/pull/6909 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2016-05-03cluster: remove use of bind() in destroy()yorkie
This commit replaces process.exit.bind() with an arrow function in Worker.prototype.destroy(). PR-URL: https://github.com/nodejs/node/pull/6502 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-25cluster: migrate from worker.suicideEvan Lucas
Replace it with worker.exitedAfterDisconnect. Print deprecation message when getting or setting until it is removed. PR-URL: https://github.com/nodejs/node/pull/3743 Fixes: https://github.com/nodejs/node/issues/3721 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2016-03-23lib: refactor code with startsWith/endsWithJackson Tian
reduce using RegExp for string test. This pull reuqest replaces various usages of regular expressions in favor of the ES2015 startsWith and endsWith methods. PR-URL: https://github.com/nodejs/node/pull/5753 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-02-25cluster: emit worker as first 'message' event argBen Noordhuis
It's documented as such but didn't actually behave that way. Bug introduced in commit 66fc8ca ("cluster: emit 'message' event on cluster master"), which is the commit that introduced the event. Fixes: https://github.com/nodejs/node/issues/5126 PR-URL: https://github.com/nodejs/node/pull/5361 Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-02-16cluster: dont rely on `this` in `fork`Igor Klopov
PR-URL: https://github.com/nodejs/node/pull/5216 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
2016-01-13cluster: fix race condition setting suicide propSantiago Gimeno
There is no guarantee that the `suicide` property of a worker in the master process is going to be set when the `disconnect` and `exit` events are emitted. To fix it, wait for the ACK of the suicide message from the master before disconnecting the worker. Also, there's no need to send the suicide message from the worker if the disconnection has been initiated in the master. Add `test-cluster-disconnect-suicide-race` that forks a lot of workers to consistently reproduce the issue this patch tries to solve. Modify `test-regress-GH-3238` so it checks both the `kill` and `disconnect` cases. Also take into account that the `disconnect` event may be received after the `exit` event. PR-URL: https://github.com/nodejs/node/pull/4349 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
2016-01-07cluster: ignore queryServer msgs on disconnectionSantiago Gimeno
It avoids the creation of unnecessary handles. This issue is causing intermitent failures in `test-cluster-disconnect-race` on `FreeBSD` and `OS X`. The problem is that the `worker2.disconnect` is being called on the master before the `queryServer` is handled, causing the worker to be deleted, then the Server handle is created afterwards. Later on, when `removeWorker` is called from the `exit` handler, there are no workers left, but one handle, thus the `AssertionError`. Add a new `test/sequential/test-cluster-disconnect-leak` based on `test-cluster-disconnect-race` that creates lots of workers and fails consistently without this patch. PR-URL: https://github.com/nodejs/node/pull/4465 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Rich Trott <rtrott@gmail.com>
2015-12-17lib: use arrow functions instead of bindMinwoo Jung
use `arrow functions` instead of `bind(this)` in order to improve performance through optimizations. PR-URL: https://github.com/nodejs/node/pull/3622 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
2015-11-11cluster: send suicide message on disconnectcjihrig
This commit causes Worker.prototype.disconnect() to send a suicide message to the cluster master. The function is also restructured to eliminate redundant code. Fixes: https://github.com/nodejs/node/issues/3238 PR-URL: https://github.com/nodejs/node/pull/3720 Reviewed-By: James M Snell <jasnell@gmail.com>
2015-11-06cluster: remove handles when disconnecting workerBen Noordhuis
Due to the race window between the master's "disconnect" message and the worker's "handle received" message, connections sometimes got stuck in the pending handles queue when calling `worker.disconnect()` in the master process. The observable effect from the client's perspective was a TCP or HTTP connection that simply stalled. This commit fixes that by closing open handles in the master when the "disconnect" message is sent. Fixes: https://github.com/nodejs/node/issues/3551 PR-URL: https://github.com/nodejs/node/pull/3677 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2015-10-27lib,test: update let to const where applicableSakthipriyan Vairamani
As per the `prefer-const` eslint rule, few instances of `let` have been identified to be better with `const`. This patch updates all those instances. Refer: https://github.com/nodejs/node/issues/3118 PR-URL: https://github.com/nodejs/node/pull/3152 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
2015-10-27lib: fix cluster handle leakRich Trott
It is possible to cause a resource leak in SharedHandle. This commit fixes the leak. Fixes: https://github.com/nodejs/node/issues/2510 PR-URL: https://github.com/nodejs/node/pull/3510 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-09-23lib,src: remove usage of events.EventEmitterSakthipriyan Vairamani
The `events` module already exports `EventEmitter` constructor function So, we don't have to use `events.EventEmitter` to access it. Refer: https://github.com/nodejs/node/pull/2896 PR-URL: https://github.com/nodejs/node/pull/2921 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
2015-09-07cluster: allow shared reused dgram socketsFedor Indutny
Allow listening on reused dgram ports in cluster workers. Fix: https://github.com/joyent/node/issues/9261 PR-URL: https://github.com/nodejs/node/pull/2548 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-04cluster: do not unconditionally set --debug-portcjihrig
Currently, each cluster worker is assigned an ever increasing --debug-port argument. A long running cluster application that does not use the debugger can run into errors related to the port range. This commit mitigates the problem by only setting the debug port if the master is started with debug arguments, or the user explicitly defines debug arguments for the worker. This commit also adds a new debug port offset counter that is only incremented when a worker is created that utilizes debugging. Fixes: https://github.com/joyent/node/issues/8159 Refs: https://github.com/nodejs/io.js/pull/1524 PR-URL: https://github.com/nodejs/io.js/pull/1949 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Oleg Elifantiev <oleg@elifantiev.ru>
2015-07-30cluster: add handle ref/unref stubs in rr modeBen Noordhuis
Add ref() and unref() stub methods to the faux handle in round-robin mode. Fixes the following TypeError when calling `server.unref()` in the worker: net.js:1521 this._handle.unref(); ^ TypeError: this._handle.unref is not a function at Server.unref (net.js:1521:18) No actual reference counting is implemented. It would effectively be a no-op because the control channel would still keep the worker alive. Fixes: https://github.com/nodejs/node/issues/73 PR-URL: https://github.com/nodejs/io.js/pull/2274 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-07-23cluster: emit 'message' event on cluster masterSam Roberts
For consistency with the worker 'exit', 'online', 'disconnect', and 'listening' events which are emitted on worker and cluster, also emit 'message' on cluster. Reviewed-by: Sam Roberts <vieuxtech@gmail.com> Reviewed-by: Christian Tellnes <christian@tellnes.no> Reviewed-by: Stephen Belanger <admin@stephenbelanger.com> PR-URL: https://github.com/nodejs/io.js/pull/861
2015-06-09cluster: wait on servers closing before disconnectOleg Elifantiev
Before this, cluster behaves not the way it is documented. When disconnect is triggered, worker must wait for every server is closed before doing disconnect actually. Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> PR-URL: https://github.com/nodejs/io.js/pull/1400 Fixes: https://github.com/nodejs/io.js/issues/1305
2015-05-09lib: fix eslint stylesYosuke Furukawa
PR-URL: https://github.com/iojs/io.js/pull/1539 Fixes: https://github.com/iojs/io.js/issues/1253 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2015-05-08cluster: disconnect event not emitted correctlyOleg Elifantiev
Inside of a worker, disconnect event was not emitted on cluster.worker Fixes: https://github.com/iojs/io.js/issues/1304 PR-URL: https://github.com/iojs/io.js/pull/1386 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-04-15node: allow multiple arguments passed to nextTickTrevor Norris
PR-URL: https://github.com/iojs/io.js/pull/1077 Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
2015-04-09lib: reduce process.binding() callsBrendan Ashworth
This commit better handles calls to process.binding() in lib/ by no longer lazy loading the bindings (the load times themselves are rather miniscule compared to the load time of V8) and never reloading the bindings (which is 172 times slower than referencing a variable with the same value). PR-URL: https://github.com/iojs/io.js/pull/1367 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-31lib: reduce util.is*() usagecjihrig
Many of the util.is*() methods used to check data types simply compare against a single value or the result of typeof. This commit replaces calls to these methods with equivalent checks. This commit does not touch calls to the more complex methods (isRegExp(), isDate(), etc.). Fixes: https://github.com/iojs/io.js/issues/607 PR-URL: https://github.com/iojs/io.js/pull/647 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21lib: use const to define constantscjihrig
This commit replaces a number of var statements throughout the lib code with const statements. PR-URL: https://github.com/iojs/io.js/pull/541 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-19cluster: avoid race enabling debugger in workerTimothy J Fontaine
Previously if a worker's state machine had already transitioned into the 'listening' state when it received the message enabling the debugger, the worker would never enable its debugger. Change the logic to allow the 'listening' as a valid state for enabling the debugger. Fixes: https://github.com/joyent/node/issues/6440 Original-PR-URL: https://github.com/joyent/node/pull/9037 Signed-off-by: Julien Gilli <julien.gilli@joyent.com> Fixes: https://github.com/iojs/io.js/issues/340 PR-URL: https://github.com/iojs/io.js/pull/501 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Bert Belder <bertbelder@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
2015-01-12Remove excessive copyright/license boilerplateisaacs
The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
2015-01-12lib: make --debug-port work with clusterBen Noordhuis
Make the cluster module intercept the `--debug-port=<port>` command line switch and replace it with the debug port of the child process. A happy coincidence of this change is that it finally makes it possible to run the sequential/test-debug-signal-cluster in parallel, it now no longer needs the default port numbers. PR-URL: https://github.com/iojs/io.js/pull/306 Reviewed-By: Miroslav Bajtoš <miroslav@strongloop.com>
2015-01-10cluster: cluster.disconnect() should check statusSam Roberts
Workers that are already disconnected but not yet exited should not be disconnected, trying to do so raises exceptions. PR-URL: https://github.com/joyent/node/pull/8642 Reviewed-by: Bert Belder <bertbelder@gmail.com>
2015-01-10cluster: don't assume all workers bind same portsSam Roberts
For shared handles that do not get connection close messages (UDP/dgram is the only example of this), cluster must not assume that a port listened on by one worker is listened on by all workers. PR-URL: https://github.com/joyent/node/pull/8642 Reviewed-by: Bert Belder <bertbelder@gmail.com>
2014-11-22lib: turn on strict modeBen Noordhuis
Turn on strict mode for the files in the lib/ directory. It helps catch bugs and can have a positive effect on performance. PR-URL: https://github.com/node-forward/node/pull/64 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-08cluster: do not signal children in debug modeFedor Indutny
Do not send signal to children if they are already in debug mode. Node.js on Windows does not register signal handler, and thus calling `process._debugProcess()` will throw an error. Reviewed-By: Trevor Norris <trevnorris@gmail.com> PR-URL: https://github.com/joyent/node/pull/8476
2014-09-03src: be more intelligent about use of "arguments"Trevor Norris
Use 'use strict' when there are named arguments and the arguments object is passed to apply(). Also pass named arguments to call() when the named argument is modified by the function. Suggested in https://github.com/joyent/node/pull/8302#issuecomment-54331801 Confirmed in https://github.com/joyent/node/pull/8302#issuecomment-54364818 Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-09-02cluster: centralize removal from workers list.Julien Gilli
Currently, cluster workers can be removed from the workers list in three different places: - In the exit event handler for the worker process. - In the disconnect event handler of the worker process. - In the disconnect event handler of the cluster master. However, handles for a given worker are cleaned up only in one of these places: in the cluster master's disconnect event handler. Because these events happen asynchronously, it is possible that the workers list is empty before we even clean up one handle. This makes the assert that makes sure that no handle is left when the workers list is empty fail. This commit removes the worker from the cluster.workers list only when the worker is dead _and_ disconnected, at which point we're sure that its associated handles are cleaned up. Fixes #8191 and #8192. Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-08-01cluster: support options in Worker constructorcjihrig
This commit moves some common Worker code into the constructor via support for an options argument. Reviewed-By: Fedor Indutny <fedor@indutny.com>