-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add socket_connect_timeout option. #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@bengl LGTM would you please rebase and add some tests? |
9584ce6
to
9fe72a3
Compare
Rebased :) |
} | ||
|
||
if (exports.debug_mode) { | ||
console.log("Stream timeout " + this.address + " id " + this.connection_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
debug("Stream timeout " + this.address + " id " + this.connection_id);
instead
@benjie shouldn't it be enough if you just manipulate the socket timeout with the parameter? What you want to reach is to have a individual timeout instead of the system one, so everything else should stay the same? And a test could be written by checking the system timeout (use a before, create a client that can't connect and check for the timeout and safe that value). Now you can increase or decrease that value as you want and do the same again and check that the timeout triggered at another time. |
What endpoint should I use that it times out connecting to? I think a closed port won't do because it'll just drop the connection immediately (no chance for a timeout) so it'd need to be one that drops the packets. Adding an |
9fe72a3
to
cb45ca4
Compare
( |
You could mock the stream :) Google just gave me this: https://gist.github.com/mjackson/1201196 |
@benjie I used your work to use the connection_timeout as socket timeout if explicitly provided and mentioned you in the changelog. That way we do not have to add another option and most people thought the connection timeout would also set a socket timeout. Thx a lot for your help! |
Thanks @BridgeAR; sorry I didn't get around to writing the tests yet but your solution's probably better anyway! 😄 |
Hey @BridgeAR; I think your fix serves a different purpose to my PR - I want the connection attempt to fail, be closed, and then attempt again in a much tighter loop than the OS default (like every 30 seconds rather than 180); whereas |
This should really be reopened |
No problem :) |
This allows you to specify the connection timeout for the stream; note that once the stream is connected the existing code performs
stream.setTimeout(0)
thereby preventing this patch triggering an idle timeout on an established connection. (This is also why I called itsocket_connect_timeout
rather than simplysocket_timeout
.)I added
this.stream.setTimeout
toinstall_stream_listeners
as it seemed the DRY-est place to put it since it is called for all streams just after they're created. If this is not the right place, please let me know.