-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cluster: fix edge cases that throw ERR_INTERNAL_ASSERTION
Some cases use both `cluster` and `net`/`cluser` will throw ERR_INTERNAL_ASSERTION when `listen`/`bind` to the port of `0`. This PR maitains a separate map of the index to fix the issue. See the new tests added for the detail cases. PR-URL: #36764 Reviewed-By: Antoine du Hamel <[email protected]>
- Loading branch information
Showing
3 changed files
with
97 additions
and
13 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,40 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const Countdown = require('../common/countdown'); | ||
if (common.isWindows) | ||
common.skip('dgram clustering is currently not supported on Windows.'); | ||
|
||
const cluster = require('cluster'); | ||
const dgram = require('dgram'); | ||
|
||
// Test an edge case when using `cluster` and `dgram.Socket.bind()` | ||
// the port of `0`. | ||
const kPort = 0; | ||
|
||
function child() { | ||
const kTime = 2; | ||
const countdown = new Countdown(kTime * 2, () => { | ||
process.exit(0); | ||
}); | ||
for (let i = 0; i < kTime; i += 1) { | ||
const socket = new dgram.Socket('udp4'); | ||
socket.bind(kPort, common.mustCall(() => { | ||
// `process.nextTick()` or `socket2.close()` would throw | ||
// ERR_SOCKET_DGRAM_NOT_RUNNING | ||
process.nextTick(() => { | ||
socket.close(countdown.dec()); | ||
const socket2 = new dgram.Socket('udp4'); | ||
socket2.bind(kPort, common.mustCall(() => { | ||
process.nextTick(() => { | ||
socket2.close(countdown.dec()); | ||
}); | ||
})); | ||
}); | ||
})); | ||
} | ||
} | ||
|
||
if (cluster.isMaster) | ||
cluster.fork(__filename); | ||
else | ||
child(); |
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,31 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const Countdown = require('../common/countdown'); | ||
const cluster = require('cluster'); | ||
const net = require('net'); | ||
|
||
// Test an edge case when using `cluster` and `net.Server.listen()` to | ||
// the port of `0`. | ||
const kPort = 0; | ||
|
||
function child() { | ||
const kTime = 2; | ||
const countdown = new Countdown(kTime * 2, () => { | ||
process.exit(0); | ||
}); | ||
for (let i = 0; i < kTime; i += 1) { | ||
const server = net.createServer(); | ||
server.listen(kPort, common.mustCall(() => { | ||
server.close(countdown.dec()); | ||
const server2 = net.createServer(); | ||
server2.listen(kPort, common.mustCall(() => { | ||
server2.close(countdown.dec()); | ||
})); | ||
})); | ||
} | ||
} | ||
|
||
if (cluster.isMaster) | ||
cluster.fork(__filename); | ||
else | ||
child(); |