Repository navigation
tcp socket localPort option does not work #15084
Description
Activity
- addednetIssues and PRs related to the net subsystem.Issues and PRs related to the net subsystem.
on Aug 30, 2017 I can reproduce this with master. I think this is similar to what
tries to address. I will open a PR fixing this shortly (the fix is causing other tests to fail because they are depending on this bug...).Lines 1383 to 1390 in 2154a3c
// EADDRINUSE may not be reported until we call listen(). To complicate // matters, a failed bind() followed by listen() will implicitly bind to // a random port. Ergo, check that the socket is bound to the expected // port before calling listen(). // // FIXME(bnoordhuis) Doesn't work for pipe handles, they don't have a // getsockname() method. Non-issue for now, the cluster module doesn't // really support pipes anyway. Reacted by Mohit Agrawal- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Aug 30, 2017 After the fix, will it throw EADDRINUSE or use the port 6002 (in above example code) ?
It will throw EADDRINUSE when the
localAddressoption ofnet.connect(options, cb)is specified as the same as thehostpassed tolisten(port, host, cb).It will use the port 6002 if neitherEDIT: oops, the defaulthostnorlocalAddressis specified because libuv setsSO_REUSEADDRon TCP sockets, so we will be connecting fromlocalhost(default ofsocket.connect) to the unspecified address, which is allowed.localAddressofsocket.connectis also the unspecified address...so it will throw if neither is specified. If only one of them is unspecified,SO_REUSEADDRwould allow the client to bind to that port.So in the example above, it will use 6002 if I set
localAddressto127.0.0.1(I don't use the IPv6-prefixed version because my current ISP does not support IPv6, although I think it should work either way. Note thataddressis not a valid option tosocket.connect(), I guess what you are trying to set islocalAddress?). Also the snippet does not close the servers so running it again after killing it will probably result inEADDRINUSEif those sockets are still inTIME_WAITstate.Also I am getting consistent errors with these tests with master after running the tests with my patch...I am pretty sure this is caused by #14781 , still investigating..
See errors
=== release test-http-client-req-error-dont-double-fire === Path: parallel/test-http-client-req-error-dont-double-fire Mismatched <anonymous> function calls. Expected exactly 1, actual 0. at Object.exports.mustCall (/Users/joyee/projects/node/test/common/index.js:477:10) at Object.<anonymous> (/Users/joyee/projects/node/test/parallel/test-http-client-req-error-dont-double-fire.js:10:24) at Module._compile (module.js:573:30) at Object.Module._extensions..js (module.js:584:10) at Module.load (module.js:507:32) at tryModuleLoad (module.js:470:12) at Function.Module._load (module.js:462:3) at Function.Module.runMain (module.js:609:10) at startup (bootstrap_node.js:202:16) Mismatched <anonymous> function calls. Expected exactly 1, actual 0. at Object.exports.mustCall (/Users/joyee/projects/node/test/common/index.js:477:10) at Object.<anonymous> (/Users/joyee/projects/node/test/parallel/test-http-client-req-error-dont-double-fire.js:14:40) at Module._compile (module.js:573:30) at Object.Module._extensions..js (module.js:584:10) at Module.load (module.js:507:32) at tryModuleLoad (module.js:470:12) at Function.Module._load (module.js:462:3) at Function.Module.runMain (module.js:609:10) at startup (bootstrap_node.js:202:16) Command: out/Release/node /Users/joyee/projects/node/test/parallel/test-http-client-req-error-dont-double-fire.js === release test-net-better-error-messages-port-hostname === Path: parallel/test-net-better-error-messages-port-hostname assert.js:41 throw new errors.AssertionError({ ^ AssertionError [ERR_ASSERTION]: 'EADDRNOTAVAIL' === 'ENOTFOUND' at Socket.<anonymous> (/Users/joyee/projects/node/test/parallel/test-net-better-error-messages-port-hostname.js:12:10) at Socket.<anonymous> (/Users/joyee/projects/node/test/common/index.js:509:15) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) Command: out/Release/node /Users/joyee/projects/node/test/parallel/test-net-better-error-messages-port-hostname.js === release test-net-connect-immediate-finish === Path: parallel/test-net-connect-immediate-finish assert.js:41 throw new errors.AssertionError({ ^ AssertionError [ERR_ASSERTION]: 'ETIMEDOUT' === 'ENOTFOUND' at Socket.client.once.common.mustCall (/Users/joyee/projects/node/test/parallel/test-net-connect-immediate-finish.js:35:10) at Socket.<anonymous> (/Users/joyee/projects/node/test/common/index.js:509:15) at Object.onceWrapper (events.js:316:30) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) Command: out/Release/node /Users/joyee/projects/node/test/parallel/test-net-connect-immediate-finish.js [02:00|% 100|+ 1805|- 3]: Done make: *** [test] Error 1EDIT: uh, I am stuck with a DNS-hijacking ISP again and that's what has been failing my tests :/
Reacted by Refael Ackermann, emcee-ai and Etienne- added a commit that references this issue
on Sep 3, 2017 - added a commit that references this issue
on Sep 5, 2017 - added a commit that references this issue
on Sep 10, 2017
Version: v6.11.2
Platform: Linux workstation 4.4.0-92-generic #115-Ubuntu SMP Thu Aug 10 09:04:33 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Subsystem: net
Output: Server 6001: socket connected 35372
Expected: Server 6001: socket connected 6002 (or EADDRINUSE error)