-
Couldn't load subscription status.
- Fork 253
Set a connect_timeout for the creation of a socket #243
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
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? |
lib/net/ldap/connection.rb
Outdated
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! |
lib/net/ldap/connection.rb
Outdated
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
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: