mirror of
https://github.com/apache/httpd.git
synced 2025-08-05 16:55:50 +03:00
Work around broken cache management in mod_ldap: If LDAPSharedCacheSize is too
small, try to free some memory by purging the cache and log a warning. Also increase the default LDAPSharedCacheSize to 500000. This is a more realistic size suitable for the default values of 1024 for LdapCacheEntries and LdapOpCacheEntries. PR: 46749 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@822458 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -442,6 +442,7 @@ void *util_ald_cache_fetch(util_ald_cache_t *cache, void *payload)
|
||||
void *util_ald_cache_insert(util_ald_cache_t *cache, void *payload)
|
||||
{
|
||||
unsigned long hashval;
|
||||
void *tmp_payload;
|
||||
util_cache_node_t *node;
|
||||
|
||||
/* sanity check */
|
||||
@@ -454,21 +455,68 @@ void *util_ald_cache_insert(util_ald_cache_t *cache, void *payload)
|
||||
util_ald_cache_purge(cache);
|
||||
if (cache->numentries >= cache->maxentries) {
|
||||
/* if the purge was not effective, we leave now to avoid an overflow */
|
||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
|
||||
"Purge of LDAP cache failed");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* should be safe to add an entry */
|
||||
if ((node = (util_cache_node_t *)util_ald_alloc(cache, sizeof(util_cache_node_t))) == NULL) {
|
||||
return NULL;
|
||||
node = (util_cache_node_t *)util_ald_alloc(cache,
|
||||
sizeof(util_cache_node_t));
|
||||
if (node == NULL) {
|
||||
/*
|
||||
* XXX: The cache management should be rewritten to work
|
||||
* properly when LDAPSharedCacheSize is too small.
|
||||
*/
|
||||
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
|
||||
"LDAPSharedCacheSize is too small. Increase it or "
|
||||
"reduce LDAPCacheEntries/LDAPOpCacheEntries!");
|
||||
if (cache->numentries < cache->fullmark) {
|
||||
/*
|
||||
* We have not even reached fullmark, trigger a complete purge.
|
||||
* This is still better than not being able to add new entries
|
||||
* at all.
|
||||
*/
|
||||
cache->marktime = apr_time_now();
|
||||
}
|
||||
util_ald_cache_purge(cache);
|
||||
node = (util_cache_node_t *)util_ald_alloc(cache,
|
||||
sizeof(util_cache_node_t));
|
||||
if (node == NULL) {
|
||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
|
||||
"Could not allocate memory for LDAP cache entry");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Take a copy of the payload before proceeeding. */
|
||||
payload = (*cache->copy)(cache, payload);
|
||||
if (!payload) {
|
||||
util_ald_free(cache, node);
|
||||
return NULL;
|
||||
tmp_payload = (*cache->copy)(cache, payload);
|
||||
if (tmp_payload == NULL) {
|
||||
/*
|
||||
* XXX: The cache management should be rewritten to work
|
||||
* properly when LDAPSharedCacheSize is too small.
|
||||
*/
|
||||
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
|
||||
"LDAPSharedCacheSize is too small. Increase it or "
|
||||
"reduce LDAPCacheEntries/LDAPOpCacheEntries!");
|
||||
if (cache->numentries < cache->fullmark) {
|
||||
/*
|
||||
* We have not even reached fullmark, trigger a complete purge.
|
||||
* This is still better than not being able to add new entries
|
||||
* at all.
|
||||
*/
|
||||
cache->marktime = apr_time_now();
|
||||
}
|
||||
util_ald_cache_purge(cache);
|
||||
tmp_payload = (*cache->copy)(cache, payload);
|
||||
if (tmp_payload == NULL) {
|
||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
|
||||
"Could not allocate memory for LDAP cache value");
|
||||
util_ald_free(cache, node);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
payload = tmp_payload;
|
||||
|
||||
/* populate the entry */
|
||||
cache->inserts++;
|
||||
|
Reference in New Issue
Block a user