From 44c5e6d4600944b494fb260616826bf939943751 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Thu, 17 Oct 2024 23:11:41 +0800 Subject: [PATCH] lib: add flag to drop connection when running in cluster mode PR-URL: https://github.com/nodejs/node/pull/54927 Refs: https://github.com/nodejs/node/issues/54882 Reviewed-By: Matteo Collina --- doc/api/net.md | 17 +++++++++++++-- lib/internal/cluster/child.js | 4 +++- ...-net-server-drop-connections-in-cluster.js | 21 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-net-server-drop-connections-in-cluster.js diff --git a/doc/api/net.md b/doc/api/net.md index 9d7ad185549cb7..272705e80edea0 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -603,12 +603,25 @@ changes: * {integer} -Set this property to reject connections when the server's connection count gets -high. +When the number of connections reaches the `server.maxConnections` threshold: + +1. If the process is not running in cluster mode, Node.js will close the connection. + +2. If the process is running in cluster mode, Node.js will, by default, route the connection to another worker process. To close the connection instead, set \[`server.dropMaxConnection`]\[] to `true`. It is not recommended to use this option once a socket has been sent to a child with [`child_process.fork()`][]. +### `server.dropMaxConnection` + + + +* {boolean} + +Set this property to `true` to begin closing connections once the number of connections reaches the \[`server.maxConnections`]\[] threshold. This setting is only effective in cluster mode. + ### `server.ref()`