Bug 58037 - LDAP module leaks connections when LDAPConnectionPoolTTL is zero
Summary: LDAP module leaks connections when LDAPConnectionPoolTTL is zero
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_ldap (show other bugs)
Version: 2.4.12
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2015-06-15 14:18 UTC by Ted Phelps
Modified: 2015-06-18 17:09 UTC (History)
0 users



Attachments
Proposed fix (530 bytes, text/plain)
2015-06-15 14:20 UTC, Ted Phelps
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ted Phelps 2015-06-15 14:18:02 UTC
My team uses apache for our Subversion server, and apache is configured to authenticate users against an LDAP server.  After a recent upgrade from 2.2 to 2.4, we noticed that it would take longer and longer to check out a large repository.  We currently have the LDAPConnectionPoolTTL set to 0 to work around a separate issue, which turns out to be important.

I recently investigated and found that uldap_connection_find was taking more and more time, and that the number of entries in st->connections was increasing by one on each authentication request.  After stepping through the code with gdb, I noticed that the calls to apr_thread_mutex_trylock always indicate that they're busy.  Each call to the function traverses the entire list of connections (twice) and finds each one locked.  It then creates and returns a new entry.

Looking at uldap_connection_close, I see that the lock is released only if ldc->keep is non-zero.  But that field will be set to zero if st->connection_pool_ttl is zero, as it is in our configuration.  One way to fix the problem would be to shift the unlock operation out of the else block, and that does resolve the issue for us.  I'll attach a patch shortly.

It should be easy enough to reproduce this issue given access to an LDAP server.  Simply configure httpd to not pool connections, and time how long it takes to make a request that triggers the LDAP authentication.  Then make tens of thousands of such requests and test again.
Comment 1 Ted Phelps 2015-06-15 14:20:02 UTC
Created attachment 32823 [details]
Proposed fix

I'm attaching a simple patch that causes uldap_connection_close to always unlock the newly-closed connection.  This resolves the issue we were seeing, and doesn't appear to introduce any new issues.
Comment 2 Eric Covener 2015-06-15 14:28:44 UTC
(In reply to Ted Phelps from comment #1)
> Created attachment 32823 [details]
> Proposed fix
> 
> I'm attaching a simple patch that causes uldap_connection_close to always
> unlock the newly-closed connection.  This resolves the issue we were seeing,
> and doesn't appear to introduce any new issues.

thanks, taking a look soon. Please followup if no activity
Comment 3 Yann Ylavic 2015-06-18 17:09:06 UTC
Backported to upcoming 2.4.15 in r1686275.