From 59f2e8d5b3545da8238b490d6d29b75d4f188321 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 | 19 +++++++++++++++-- lib/internal/cluster/child.js | 4 +++- ...-net-server-drop-connections-in-cluster.js | 21 +++++++++++++++++++ 3 files changed, 41 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..939bdd8b8b35df 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -599,12 +599,27 @@ changes: * {integer} -Set this property to reject connections when the server's connection count gets -high. +When the number of connections reaches the threshold of `server.maxConnections`. + +1. Node.js will close the connection if the process is not running in cluster mode. +2. Node.js will send the connection to other worker process by default if the process + is running in cluster mode, you can set `server.dropMaxConnection` to `true` to + close the connection. 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 close the connection when the number of connections +reaches the threshold of `server.maxConnections`. It only works in cluster mode. + ### `server.ref()`