-
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
- Loading branch information
1 parent
5e443d7
commit c9c55ef
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: server1.address().address, | ||
port: server1.address().port, | ||
localAddress: server2.address().address, | ||
localPort: server2.address().port | ||
}, common.mustNotCall()); | ||
|
||
client.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.code, 'EADDRINUSE'); | ||
server1.close(); | ||
server2.close(); | ||
})); | ||
})); | ||
})); |