-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cluster: fix cluster rr distribute error
PR-URL: #44202 Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
const cluster = require('cluster'); | ||
const rr = require('internal/cluster/round_robin_handle'); | ||
|
||
if (cluster.isPrimary) { | ||
const distribute = rr.prototype.distribute; | ||
rr.prototype.distribute = function(err, handle) { | ||
assert.strictEqual(err, 0); | ||
handle.close(); | ||
distribute.call(this, -1, undefined); | ||
}; | ||
cluster.schedulingPolicy = cluster.SCHED_RR; | ||
cluster.fork(); | ||
} else { | ||
const server = net.createServer(common.mustNotCall()); | ||
server.listen(0, common.mustCall(() => { | ||
|
||
const socket = net.connect(server.address().port); | ||
|
||
socket.on('close', common.mustCall(() => { | ||
server.close(common.mustCall(() => { | ||
process.disconnect(); | ||
})); | ||
})); | ||
})); | ||
} |