From 446f9ff3e9bd57dbbe70c8fcfe75cff562a929c1 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Sat, 14 Sep 2024 00:25:10 +0800 Subject: [PATCH] lib: add flag to drop connection when running in cluster mode --- 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 03d29170bc495c..b8f0df08130f53 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -599,12 +599,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()`