Connection failures with JNDI LDAP in Glassfish

Hi all,

I’ve written a bit of code to access an LDAP server from my
JRuby/Rails app via a Glassfish external JNDI resource - I’ve been
using the pure-ruby gem ruby-net-ldap, but since I need to use SSL and
do more than one lookup in a request, that’s ended up pretty slow
(~0.5s per lookup).

The guts of the code is here:

http://gist.github.com/88728

It’s working pretty well: it’s fast, and the LDAP server configuration
gets to be in Glassfish rather than my app, but there’s one problem:
even though I believe I’m closing the resultset and context, the
underlying LDAP connection isn’t closed. Eventually the server kills
it off for being idle, but the context is still alive, and so all
requests fail from that point, until I either reconfigure the external
resource, or restart Glassfish.

I’m running with pooling disabled, as far as I can tell, but the
connection doesn’t get closed after each request.

I do want to use pooling if possible though. The failure ends up as a
CommunicationException, and I can catch that fine in this code, but I
can’t see how I can do a “close and reopen” on the context I get from
the JNDI lookup when that happens.

Any ideas?

Thanks,
Chris.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Chris A. wrote:

It’s working pretty well: it’s fast, and the LDAP server configuration
gets to be in Glassfish rather than my app, but there’s one problem:
even though I believe I’m closing the resultset and context, the
underlying LDAP connection isn’t closed. Eventually the server kills
it off for being idle, but the context is still alive, and so all
requests fail from that point, until I either reconfigure the external
resource, or restart Glassfish.

I notice the close calls in ldap_search aren’t in an ensure. Are they
being reached? Is it possible an error is bubbling out but getting
swallowed somewhere? Note also that you’re yielding results…are you
perhaps doing a return in the yielded block? That would immediately jump
back to the caller, skipping those close calls.

To be sure the close calls are hit, put the while stuff in begin and the
close calls in an ensure block.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email