mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 22:40:57 +00:00

PR-URL: https://github.com/nodejs/node/pull/15097 Fixes: https://github.com/nodejs/node/issues/15084 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
27 lines
818 B
JavaScript
27 lines
818 B
JavaScript
'use strict';
|
|
|
|
// This tests that net.connect() from a used local port throws EADDRINUSE.
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
const server1 = net.createServer(common.mustNotCall());
|
|
server1.listen(0, common.localhostIPv4, common.mustCall(() => {
|
|
const server2 = net.createServer(common.mustNotCall());
|
|
server2.listen(0, common.localhostIPv4, common.mustCall(() => {
|
|
const client = net.connect({
|
|
host: common.localhostIPv4,
|
|
port: server1.address().port,
|
|
localAddress: common.localhostIPv4,
|
|
localPort: server2.address().port
|
|
}, common.mustNotCall());
|
|
|
|
client.on('error', common.mustCall((err) => {
|
|
assert.strictEqual(err.code, 'EADDRINUSE');
|
|
server1.close();
|
|
server2.close();
|
|
}));
|
|
}));
|
|
}));
|