-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: check EADDRINUSE after binding localPort
PR-URL: #15097 Fixes: #15084 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
- Loading branch information
1 parent
d7200d6
commit c419adf
Showing
2 changed files
with
49 additions
and
14 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,26 @@ | ||
'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(); | ||
})); | ||
})); | ||
})); |