Bug 45374

Summary: Shared memory error on starting httpd with mod_ldap
Product: Apache httpd-2 Reporter: Philippe Duveau <philippe.duveau>
Component: mod_ldapAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: RESOLVED LATER    
Severity: blocker Keywords: MassUpdate, PatchAvailable
Priority: P4    
Version: 2.2.9   
Target Milestone: ---   
Hardware: PC   
OS: Windows Server 2003   

Description Philippe Duveau 2008-07-10 07:10:14 UTC
The shared cache can be enable in httpd 2.2.8 and 2.2.9.

Steps to reproduce:
==========================================

httpd.conf:

ServerRoot "D:/Apache2"
ServerName myserver.org
PidFile run/httpd.pid
ErrorLog logs/error.log
LogLevel warn
LoadModule ldap_module modules/mod_ldap.so
LDAPSharedCacheFile logs/ldap_cache
listen 80

The server stops immediatly with those logs :

[notice] Server built: May 16 2008 18:51:09
[notice] Parent: Created child process 4844
[error] (17)File exists: LDAP cache: could not create shared memory segment
Configuration Failed
[crit] master_main: create child process failed. Exiting.
[error] (OS 6)Descripteur non valide  : Parent: SetEvent for child process 0 failed


After investigation, the problem come from a fix in libapr (commit 570289, line 140 of apr/shmem/win32/shm.c)

To correct the problem you should apply the following patch :

Index: modules/ldap/util_ldap_cache.c
===================================================================
--- modules/ldap/util_ldap_cache.c	(revision 666274)
+++ modules/ldap/util_ldap_cache.c	(working copy)
@@ -404,6 +404,12 @@
     size = APR_ALIGN_DEFAULT(st->cache_bytes);
 
     result = apr_shm_create(&st->cache_shm, size, st->cache_file, st->pool);
+    if (result == APR_EEXIST) {
+		/* In case of existing cache file the apr_shm_create failed returning APR_EEXIST
+		 * So in this case, try to attach the existing file
+		 */
+	    result = apr_shm_attach(&st->cache_shm, st->cache_file, st->pool);
+    }
     if (result != APR_SUCCESS) {
         return result;
     }
Comment 1 Ruediger Pluem 2008-07-10 08:33:04 UTC
I disagree with the proposed solution in the patch. If the file already exists it could be possible that this is a misconfiguration of httpd as you can run multiple instances in parallel and the configuration can point to the file of another instance. If the file is really from the same instance the instance was not shutdown cleanly last time and this should be always a reason to investigate why.
So IMHO things work as designed here (apart from a maybe more descriptive error message).
Comment 2 Philippe Duveau 2008-07-10 10:14:31 UTC
In fact, you know like me that httpd is working with a "watch dog" and a child to do the job. In this case the problem is systematic because the shared memory is created by the watch dog (post config hook) and when the child tries to created it the shared memory is ALWAYS already existing. 

Before the version 1.2.11 of APR the test made on apr/shmem/win32/shm.c:140 was ALWAYS "false" because the two values were in two different ranges of errors (the WINAPI one <15000 and APR_OS one >720000). So even if the file was existing, it was not detect as existing. With the last versions, the detection is efficient.

So please take a time to try the proposed configuration (which is so simple that it can not contains misconfiguration) on Windows XP/2003 with an APR 1.2.11 (as proposed with 2.2.8) or more, you will see that if you launch httpd with -X (no watch dog) it works and if you launch it with the watch dog it fail to start.

Perhaps, the real solution is to create shared memory form a child_init hook instead of creating it from a post_config one. This should avoid the conflict between the "watch dog" and the child.
Comment 3 William A. Rowe Jr. 2018-11-07 21:08:04 UTC
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd.

As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd.

If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question.

If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with.

Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.