-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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 <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>
- Loading branch information
1 parent
23df8fc
commit 24f06c5
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(); | ||
})); | ||
})); | ||
})); |