Skip to content
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

Respect connect_timeout when establishing SSL connections #273

Merged
merged 5 commits into from
Jul 13, 2016

Conversation

tmm1
Copy link
Contributor

@tmm1 tmm1 commented Jun 15, 2016

cc #243

@tmm1 tmm1 force-pushed the ssl-connect-timeout branch from 22fa81c to a742ffe Compare June 15, 2016 23:51
@tmm1 tmm1 force-pushed the ssl-connect-timeout branch from a742ffe to 09d0c36 Compare June 15, 2016 23:54
@tmm1 tmm1 force-pushed the ssl-connect-timeout branch from d192a85 to b5b6d5a Compare June 16, 2016 01:03
if IO.select([conn], nil, nil, timeout)
retry
else
raise Net::LDAP::LdapError, "OpenSSL connection read timeout"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Net::LDAP::LdapError is deprecated so please use Net::LDAP::Error instead.
I as a user of net-ldap want new exception class for timeout to let us handle cases where connection timeout happens. lib/net/ldap/error.rb would help you, I think.

Copy link
Contributor Author

@tmm1 tmm1 Jun 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to SocketError, but I can add a new TimeoutError or return ETIMEDOUT if that makes more sense.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errorno::ETIMEDOUT makes more sense in terms of compatibility since TCPSocket raises Errorno::ETIMEDOUT.

@jch @mtodd how do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, switched to Errno::ETIMEDOUT

@sgringwe
Copy link

@tmm1 may i ask what prompted this PR? I recently ran into issues when using puma (rather than unicorn) for an application which uses LDAP which is resulting in timeouts in the socket#connect method when binding and searching. hoping this is related and could fix our issue!

sgringwe added a commit to joinhandshake/ruby-net-ldap that referenced this pull request Jun 21, 2016
@@ -291,7 +291,7 @@ def test_queued_read_setup_encryption_with_start_tls
and_return(result2)
mock.should_receive(:write)
conn = Net::LDAP::Connection.new(:socket => mock)
flexmock(Net::LDAP::Connection).should_receive(:wrap_with_ssl).with(mock, {}).
flexmock(Net::LDAP::Connection).should_receive(:wrap_with_ssl).with(mock, {}, nil).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmm1 Doesn't this mocking cover your changes on wrap_with_ssl, do ti? If you tested your changes work as you expected, could you share how to do it?

I know it's really hard to reproduce the situation timeout or something network issues happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the change by setting a very low timeout on LDAPS connection and
make sure an exception is raised.
On Mon, Jun 20, 2016 at 10:15 PM Tatsuya Sato [email protected]
wrote:

In test/test_ldap_connection.rb
#273 (comment)
:

@@ -291,7 +291,7 @@ def test_queued_read_setup_encryption_with_start_tls
and_return(result2)
mock.should_receive(:write)
conn = Net::LDAP::Connection.new(:socket => mock)

  • flexmock(Net::LDAP::Connection).should_receive(:wrap_with_ssl).with(mock, {}).
  • flexmock(Net::LDAP::Connection).should_receive(:wrap_with_ssl).with(mock, {}, nil).

@tmm1 https://github.com/tmm1 Doesn't this mocking cover your changes
on wrap_with_ssl, do ti? If you tested your changes work as you expected,
could you share how to do it?

I know it's really hard to reproduce the situation timeout or something
network issues happens.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ruby-ldap/ruby-net-ldap/pull/273/files/749c22b4e5514ead10c92bcaec1c5a1eb49db455#r67809160,
or mute the thread
https://github.com/notifications/unsubscribe/AAAKB01CFZ0ewSejsl4qpinzGhwx48U5ks5qN3N4gaJpZM4I25cW
.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks!

@tmm1
Copy link
Contributor Author

tmm1 commented Jun 21, 2016

@tmm1 may i ask what prompted this PR? I recently ran into issues when using puma (rather than unicorn) for an application which uses LDAP which is resulting in timeouts in the socket#connect method when binding and searching. hoping this is related and could fix our issue!

Sounds like you need to set a custom connect_timeout on your LDAP connection, since the DefaultConnectTimeout is 5 seconds.

@satoryu
Copy link
Collaborator

satoryu commented Jul 4, 2016

@tmm1 sorry for late reply. Your PR looks good. but unfortunately I cannot see Merge button :(

So anybody have a look and merge this PR ? @jch @mtodd

@jch jch merged commit dd9409b into ruby-ldap:master Jul 13, 2016
@jch jch mentioned this pull request Jul 13, 2016
@tmm1 tmm1 deleted the ssl-connect-timeout branch July 14, 2016 01:12
jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Oct 17, 2016
=== Net::LDAP 0.15.0

* Respect connect_timeout when establishing SSL connections {#273}[ruby-ldap/ruby-net-ldap#273]
This was referenced Jan 24, 2023
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