8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9b7b4a6 commit db18acaCopy full SHA for db18aca
doc/api/net.md
@@ -603,12 +603,25 @@ changes:
603
604
* {integer}
605
606
-Set this property to reject connections when the server's connection count gets
607
-high.
+When the number of connections reaches the `server.maxConnections` threshold:
+
608
+1. If the process is not running in cluster mode, Node.js will close the connection.
609
610
+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`.
611
612
It is not recommended to use this option once a socket has been sent to a child
613
with [`child_process.fork()`][].
614
615
+### `server.dropMaxConnection`
616
617
+<!-- YAML
618
+added: REPLACEME
619
+-->
620
621
+* {boolean}
622
623
+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.
624
625
### `server.ref()`
626
627
<!-- YAML
lib/internal/cluster/child.js
@@ -231,7 +231,9 @@ function onconnection(message, handle) {
231
232
if (accepted && server[owner_symbol]) {
233
const self = server[owner_symbol];
234
- if (self.maxConnections != null && self._connections >= self.maxConnections) {
+ if (self.maxConnections != null &&
235
+ self._connections >= self.maxConnections &&
236
+ !self.dropMaxConnection) {
237
accepted = false;
238
}
239
test/parallel/test-net-server-drop-connections-in-cluster.js
@@ -0,0 +1,21 @@
1
+'use strict';
2
+const common = require('../common');
3
+const cluster = require('cluster');
4
+const http = require('http');
5
6
+if (cluster.isPrimary) {
7
+ cluster.fork();
8
+} else {
9
+ const server = http.createServer();
10
+ server.maxConnections = 0;
11
+ server.dropMaxConnection = true;
12
+ // When dropMaxConnection is false, the main process will continue to
13
+ // distribute the request to the child process, if true, the child will
14
+ // close the connection directly and emit drop event.
15
+ server.on('drop', common.mustCall((a) => {
16
+ process.exit();
17
+ }));
18
+ server.listen(common.mustCall(() => {
19
+ http.get(`http://localhost:${server.address().port}`).on('error', console.error);
20
21
+}