-
Notifications
You must be signed in to change notification settings - Fork 253
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
Set a connect_timeout for the creation of a socket #243
Conversation
30099e8
to
41846bb
Compare
@astratto interesting. It looks like
Yes. I don't know how to simulate a hanging connection. If you have ideas, I'd love to hear them.
Agree this should be parameterized. Thanks for opening this pull! |
I actually already have tests for our projects to trigger that situation (hence the PR 😄), I'm just not sure how to do that with the integration tests here. Basic idea is to use a firewall to drop packets.
Yes, I just wanted to understand your point of view on the general PR.
Thanks for this gem 😉 |
The entry point for integration tests on travis is in https://github.com/ruby-ldap/ruby-net-ldap/blob/master/.travis.yml#L15-L17. This then runs |
01b8309
to
a447c11
Compare
Hey @jch, I've just pushed a patch to expose :connect_timeout and :timeout. I think it's worth trying to add some integration tests for connection errors in general, should we address that in another patchset? |
@@ -31,10 +36,15 @@ def open_connection(server) | |||
hosts = server[:hosts] | |||
encryption = server[:encryption] | |||
|
|||
socket_opts = { | |||
connect_timeout: server[:connect_timeout] || DefaultConnectTimeout, | |||
timeout: server[:timeout] || DefaultTimeout |
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.
According to the doc, Socket.tcp
deals with only connect_timeout
. Does timeout
make sense?
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.
Interesting, it was there in 2.0.0... http://docs.ruby-lang.org/en/2.0.0/Socket.html#method-c-tcp
I'm gonna remove it 😄
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.
Gone 😉
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.
well-done! 👍
a447c11
to
68bdf96
Compare
👍 that's be amazing! |
@@ -3,6 +3,9 @@ | |||
class Net::LDAP::Connection #:nodoc: | |||
include Net::LDAP::Instrumentation | |||
|
|||
# Seconds before failing for socket connect timeout | |||
DefaultConnectTimeout = 1 |
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.
Could we make this value a bit more generous so it doesn't surprise any users with slow connections?
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.
Sure, it's 5 seconds now.
I doubt more than that would be of any use, but let me know if you want to bump it further.
68bdf96
to
960ad23
Compare
960ad23
to
c03e044
Compare
Okay, it was actually straightforward given that the box is used by Travis has iptables available. |
@astratto looks like there's a travis error. Could we re-run it somehow? |
@astratto this failure seems like spotify/rspec-dns#26 . so will be fixed by adding the following lines to before_install:
- gem update bundler |
This patch prevents LDAP connections to hang up for an eccessive amount of time and instead returns earlier in case of failures (e.g., packets dropped). A new option is now exposed through Net::LDAP: - connect_timeout: sets a timeout for socket#connect (defaults to 1s) It also provides an integration test to validate the new behaviour (ruby-ldap#244)
c03e044
to
f6611e2
Compare
@@ -109,4 +109,7 @@ chgrp ssl-cert /etc/ssl/private/ldap01_slapd_key.pem | |||
chmod g+r /etc/ssl/private/ldap01_slapd_key.pem | |||
chmod o-r /etc/ssl/private/ldap01_slapd_key.pem | |||
|
|||
# Drop packets on a secondary port used to specific timeout tests |
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.
👍 helpful comment
Set a connect_timeout for the creation of a socket
Looks great. I especially appreciate you taking the time to add an integration test. 🎉 |
Currently when an LDAP server is not reachable (for instance, packets are dropped), users of this library end up waiting for a quite long period of time. This is very rarely acceptable and can easily lead to a chain of failures with several services timing out before the socket creation actually fails.
This patch uses Socket.tcp instead of TCPSocket.new and provides a default connect_timeout of 1 second.
Notes: