-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: add flag to drop connection when running in cluster mode
PR-URL: #54927 Refs: #54882 Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
3 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
test/parallel/test-net-server-drop-connections-in-cluster.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const cluster = require('cluster'); | ||
const http = require('http'); | ||
|
||
if (cluster.isPrimary) { | ||
cluster.fork(); | ||
} else { | ||
const server = http.createServer(); | ||
server.maxConnections = 0; | ||
server.dropMaxConnection = true; | ||
// When dropMaxConnection is false, the main process will continue to | ||
// distribute the request to the child process, if true, the child will | ||
// close the connection directly and emit drop event. | ||
server.on('drop', common.mustCall((a) => { | ||
process.exit(); | ||
})); | ||
server.listen(common.mustCall(() => { | ||
http.get(`http://localhost:${server.address().port}`).on('error', console.error); | ||
})); | ||
} |