-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Description
Affected URL(s)
https://nodejs.org/api/net.html
Description of the problem
The documentation for the connect
method on net.Socket
(https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) says that there are options noDelay
, keepAlive
, keepAliveInitialDelay
. However, by looking at the source code, these options are in fact instead for the constructor of new net.Socket
.
Therefore, this code won't work (the last three options will be ignored):
let s = new net.Socket();
s.connect({
port: 80,
host: "[some host]",
noDelay: true,
keepAlive: true,
keepAliveInitialDelay: 60000});
Moving them to the options passed to the constructor instead will make it work.
This issue can easily be verified with strace
on Linux.
I suggest to fix the documentation to match the actual behaviour rather than changing the implementation to match the documentation. Looking at what options are available for the constructor vs. the connect method, it makes more sense to have these options in the constructor, since the connect method only have options regarding to the actual connection attempt (such as what host, port, ip family etc. to use for the connection attempt), while the socket constructor takes options to use for the socket itself, such as if half-open should be enabled etc.
It seems this issue has been present ever since these new options were added in #41310. Note that if you use the net.createConnection
factory method, you won't notice the issue since the same options are passed to both methods.