Summary: | httpd crashes while loading ldap attributes | ||
---|---|---|---|
Product: | Apache httpd-2 | Reporter: | Bernd Leinfelder <bernd.asf> |
Component: | mod_authz_ldap | Assignee: | Apache HTTPD Bugs Mailing List <bugs> |
Status: | RESOLVED FIXED | ||
Severity: | critical | CC: | covener |
Priority: | P2 | Keywords: | PatchAvailable |
Version: | 2.2.6 | ||
Target Milestone: | --- | ||
Hardware: | Other | ||
OS: | AIX | ||
Attachments: |
Patch - optimized string handling in util_ldap.c
Patch - optimized attribute handling |
Description
Bernd Leinfelder
2007-11-22 09:49:08 UTC
With additional debugging I found something new: The problem is in apr_strings.c in function apr_pstrcat, when memory is requested from apr_palloc. The last call to apr_palloc before the coredump returns 0, so memcpy tries to copy to an invalid destination. apr_palloc returns NULL if and only if allocator_alloc return NULL in apr_pools.c. This is teh case if malloc fails. So the question is: What makes malloc fail on AIX? >What makes malloc fail on AIX?
1) unavoidable address space limitations (I think the max heap is 2GB with 32-bit processes)
2) ulimits
3) starting Apache with httpd instead of apachectl, which skips the LDR_CNTRL setting in envvars, and
you're left with a default address space layout which doesn't allow much heap
(LDR_CNTRL necessity applies only to 32-bit builds)
4) out of paging space
5) ???
Created attachment 21240 [details]
Patch - optimized string handling in util_ldap.c
Problem was caused by a problematic algorithm in util_ldap.c, where for each
attribue value apr_pstrcat was called. with each call new memory was allocated,
so that in the end this operation caused an allocation of 260 mb for storing
180 kb. This was optimized in uldap_cache_getuserdn.
Can you please provide your patch as a unified diff? Jeff, your are right. We started httpd directly and so the data segment was limited to 256 MB. See http://publib.boulder.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=/com.ibm.itame.doc/am60_perftune64.htm With specifying the LDR_CNTRLs the process didn't crash anymore, but grew to a size of 760 mb during retrieving the ldap attributes. Thanks for this very helpful hint. Created attachment 21242 [details]
Patch - optimized attribute handling
Regardless of the process doesn't crash anymore with correct LDR-CNTRLs I still
think that this is bug in util_ldap.c
If you look at this piece of code:
- while (values && values[j]) {
- str = str ? apr_pstrcat(r->pool, str, "; ", values[j], NULL)
- : apr_pstrdup(r->pool, values[j]);
So with each iteration an new string is allocated with apr_pstrcat whereas the
old string is not returned to the pool.
In my case I want to retrieve 3'500 attribute values. So this loop has 3'500
iterations and 3'500 strings are allocated, each a bit larger than the one
before. This is exponential memory consumption.
In the end this loop consumes about 760 mb; in my patched version it takes only
about 800 kb. Still not optimal, but much better than before.
Patch now in unified diff format as requested.
|