diff options
author | Ouyang Yadong <oyydoibh@gmail.com> | 2018-10-27 10:44:50 +0300 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2018-12-03 21:32:55 +0300 |
commit | 56afb7b481db26ec6f86dcd3806c8bfafe78e40e (patch) | |
tree | a87949581cf933df1c062257eff65501715cb833 /test | |
parent | 8ef5de55fd5376ab544624ba47d9a8940c729eb9 (diff) |
net: `net.Server.listen()` avoid operations on `null` when fail
When `net.Server` fails to create a new handle, an error shall be
emitted in the next tick. Therefore, we make `net.Server.listen()`
directly return to avoid following operations on `null`
`this._handle`.
Fixes: https://github.com/nodejs/node/issues/23917
PR-URL: https://github.com/nodejs/node/pull/23920
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-net-server-listen-path.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/parallel/test-net-server-listen-path.js b/test/parallel/test-net-server-listen-path.js index cc73c3fd438..cc7c6678b04 100644 --- a/test/parallel/test-net-server-listen-path.js +++ b/test/parallel/test-net-server-listen-path.js @@ -69,3 +69,23 @@ function randomPipePath() { srv.close(); })); } + +// Test should emit "error" events when listening fails. +{ + const handlePath = randomPipePath(); + const srv1 = net.createServer().listen({ path: handlePath }, () => { + // As the handlePath is in use, binding to the same address again should + // make the server emit an 'EADDRINUSE' error. + const srv2 = net.createServer() + .listen({ + path: handlePath, + writableAll: true, + }, common.mustNotCall()); + + srv2.on('error', common.mustCall((err) => { + srv1.close(); + assert.strictEqual(err.code, 'EADDRINUSE'); + assert(/^listen EADDRINUSE: address already in use/.test(err.message)); + })); + }); +} |