mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
84fe809535
Unhandled `'error'` events will make the process exit with an unclean exit code anyway. PR-URL: https://github.com/nodejs/node/pull/55486 Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const { checkSupportReusePort, options } = require('../common/udp');
|
|
const assert = require('assert');
|
|
const child_process = require('child_process');
|
|
const dgram = require('dgram');
|
|
|
|
if (!process.env.isWorker) {
|
|
checkSupportReusePort().then(() => {
|
|
const socket = dgram.createSocket(options);
|
|
socket.bind(0, common.mustCall(() => {
|
|
const port = socket.address().port;
|
|
const workerOptions = { env: { ...process.env, isWorker: 1, port } };
|
|
let count = 2;
|
|
for (let i = 0; i < 2; i++) {
|
|
const worker = child_process.fork(__filename, workerOptions);
|
|
worker.on('exit', common.mustCall((code) => {
|
|
assert.strictEqual(code, 0);
|
|
if (--count === 0) {
|
|
socket.close();
|
|
}
|
|
}));
|
|
}
|
|
}));
|
|
}, () => {
|
|
common.skip('The `reusePort` is not supported');
|
|
});
|
|
return;
|
|
}
|
|
|
|
const socket = dgram.createSocket(options);
|
|
|
|
socket.bind(+process.env.port, common.mustCall(() => {
|
|
socket.close();
|
|
}));
|