Ruby-ldap timeout

Hello list,

Does anyone know if ruby-ldap supports connection timeouts? We have LDAP
integrated into our authentication system to provide LDAP authentication
well. It works fine if you input a valid host/port and if the LDAP
server is
responding ok. However, if the host doesn’t respond for some reason
be an invalid IP), ruby-ldap hangs there waiting forever, hanging the
application, something that obvisouly could cause potential problems
it uses passenger).

Any ideas on how to handle that?



Hi Marcelo,

If that ldap lib doesn’t include any timeout settings/params for
timing out long-running ldap calls (which if you’re talking about ruby-
net-ldap, it doesn’t at this time), then one way would be to wrap
those potentially-long-running calls in ruby’s timeout (http://ruby- to at least force a timeout on your
app’s side of the process, something like:

TIMEOUT_SECS = 10 # or whatever the max should be.

timeout_status = nil
timeout_status = Timeout::timeout(TIMEOUT_SECS) do
# do stuff that might take too long …
rescue Timeout::Error => te
# log it and …


On Apr 1, 11:18 am, Marcelo de Moraes S. [email protected]

Hi Jeff,

Thanks! Every single day I’m amazed by what’s possible with Ruby, the
more I
learn, the less I know, but I guess that’s good :slight_smile:

This led me to the SystemTimer gem. The Timeout class was failing, I
because it is external call that “cross the barriers”, as explained
here: SystemTimer works like a charm



Correction. SystemTimer works when binding, but does not work with the
search / search2 method(s). If the LDAP server hangs for any reason,
SystemTimer fails to kill the thread, and even though the Timeout::Error
exception is thrown, it is only after much more time than what you
define in
the timeout_after(time) method.

I’ve tried to contact Philippe, the author regarding this, let’s see how
goes. Meanwhile, if anyone has a clue on why it is failing, please



On Thu, Apr 1, 2010 at 4:09 PM, Marcelo de Moraes S.
<[email protected]


Does anyone have any idea on why it fails?


On Fri, Apr 2, 2010 at 8:50 PM, Marcelo de Moraes S.
<[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs