Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

benjie
Copy link
Contributor

@benjie benjie commented Aug 28, 2014

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 it socket_connect_timeout rather than simply socket_timeout.)

I added this.stream.setTimeout to install_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.

@BridgeAR BridgeAR self-assigned this Sep 17, 2015
@BridgeAR
Copy link
Contributor

@bengl LGTM would you please rebase and add some tests?

@bengl
Copy link
Contributor

bengl commented Sep 17, 2015

by @bengl you mean @benjie right? 😄

@BridgeAR
Copy link
Contributor

@bengl ups sorry for bringing you up :D
And yes, I meant @benjie

@benjie
Copy link
Contributor Author

benjie commented Sep 18, 2015

😆 thanks @bengl :)

@BridgeAR I'm not sure how I'd write a test for this

@benjie benjie force-pushed the socket_connect_timeout branch from 9584ce6 to 9fe72a3 Compare September 18, 2015 15:57
@benjie
Copy link
Contributor Author

benjie commented Sep 18, 2015

Rebased :)

}

if (exports.debug_mode) {
console.log("Stream timeout " + this.address + " id " + this.connection_id);
Copy link
Contributor

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

@BridgeAR
Copy link
Contributor

@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.

@benjie
Copy link
Contributor Author

benjie commented Sep 18, 2015

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 iptables filter would make the test platform dependent; is there a cross-platform /dev/null equivalent for TCP?

@benjie benjie force-pushed the socket_connect_timeout branch from 9fe72a3 to cb45ca4 Compare September 18, 2015 17:42
@benjie
Copy link
Contributor Author

benjie commented Sep 18, 2015

(debug() change implemented)

@BridgeAR
Copy link
Contributor

You could mock the stream :)

Google just gave me this: https://gist.github.com/mjackson/1201196

@BridgeAR BridgeAR closed this in dc6fc9c Oct 29, 2015
@BridgeAR
Copy link
Contributor

@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!

@benjie
Copy link
Contributor Author

benjie commented Oct 29, 2015

Thanks @BridgeAR; sorry I didn't get around to writing the tests yet but your solution's probably better anyway! 😄

@benjie
Copy link
Contributor Author

benjie commented Apr 21, 2016

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 connect_timeout stops attempting to reconnect meaning we remain disconnected forever. There may still be value in this PR

@billinghamj
Copy link

This should really be reopened

@BridgeAR
Copy link
Contributor

BridgeAR commented May 7, 2019

@benjie thanks for pointing this out and sorry for not understanding your original issue properly right away.

There seems to be a new PR to do the same: #1430

@benjie
Copy link
Contributor Author

benjie commented May 7, 2019

No problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants