-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: multiple listen() events fail silently
Problem: It's possible to run listen() on a net.Server that's already listening to a port. The result is silent failure, with the side effect of changing the connectionKey and or pipeName. Solution: throw an error if listen method called more than once. close() method should be called between listen() method calls. Refs: #8294 Fixes: #6190 Fixes: #11685 PR-URL: #13149 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
- Loading branch information
Showing
5 changed files
with
69 additions
and
9 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
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
51 changes: 51 additions & 0 deletions
51
test/parallel/test-net-server-call-listen-multiple-times.js
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,51 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
// First test. Check that after error event you can listen right away. | ||
{ | ||
const dummyServer = net.Server(); | ||
const server = net.Server(); | ||
|
||
// Run some server in order to simulate EADDRINUSE error. | ||
dummyServer.listen(common.mustCall(() => { | ||
// Try to listen used port. | ||
server.listen(dummyServer.address().port); | ||
})); | ||
|
||
server.on('error', common.mustCall((e) => { | ||
assert.doesNotThrow( | ||
() => server.listen(common.mustCall(() => { | ||
dummyServer.close(); | ||
server.close(); | ||
})) | ||
); | ||
})); | ||
} | ||
|
||
// Second test. Check that second listen call throws an error. | ||
{ | ||
const server = net.Server(); | ||
|
||
server.listen(common.mustCall(() => server.close())); | ||
|
||
common.expectsError(() => server.listen(), { | ||
code: 'ERR_SERVER_ALREADY_LISTEN', | ||
type: Error | ||
}); | ||
} | ||
|
||
// Third test. | ||
// Check that after the close call you can run listen method just fine. | ||
{ | ||
const server = net.Server(); | ||
|
||
server.listen(common.mustCall(() => { | ||
server.close(); | ||
assert.doesNotThrow( | ||
() => server.listen(common.mustCall(() => server.close())) | ||
); | ||
})); | ||
} |