Stas Bekman wrote:

Randy Kobes wrote:

On Wed, 24 Sep 2003, Stas Bekman wrote:


Sander says that this shouldn't be an issue, however try
this patch. It assigns a unique key based on the pool
address without hardcoding anything at all:

Index: xs/APR/Pool/APR__Pool.h
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/Pool/APR__Pool.h,v
retrieving revision 1.6
diff -u -r1.6 APR__Pool.h
--- xs/APR/Pool/APR__Pool.h     9 Sep 2003 17:22:39 -0000       1.6
+++ xs/APR/Pool/APR__Pool.h     25 Sep 2003 06:55:57 -0000
@@ -9,12 +9,15 @@
 {
     apr_pool_t *parent = mpxs_sv_object_deref(obj, apr_pool_t);
     apr_pool_t *newpool = NULL;
+    char *key;
+
     (void)apr_pool_create(&newpool, parent);

     /* mark the pool as being created via APR::Pool->new()
      * see mpxs_apr_pool_DESTROY */
-    apr_pool_userdata_set((const void *)1, MP_APR_POOL_NEW,
-                          apr_pool_cleanup_null, newpool);
+    key = apr_psprintf(newpool, "0x%lx", (unsigned long)newpool);
+    fprintf(stderr, "CREATE  key: %s\n", key);
+    apr_pool_userdata_set((const void *)1, key, NULL, newpool);

     return newpool;
 }
@@ -119,7 +122,8 @@

     void *flag;
     apr_pool_t *p;
-
+    char *key;
+
     /* APR::Pool::DESTROY
      * we only want to call DESTROY on objects created by
      * APR::Pool->new(), not objects representing native pools
@@ -128,7 +132,9 @@

p = mpxs_sv_object_deref(obj, apr_pool_t);

-    apr_pool_userdata_get(&flag, MP_APR_POOL_NEW, p);
+    key = apr_psprintf(p, "0x%lx", (unsigned long)p);
+    fprintf(stderr, "DESTROY key: %s\n", key);
+    apr_pool_userdata_get(&flag, key, p);

     if (flag) {
          apr_pool_destroy(p);


Do you get the printf reporting unique addresses, which are used as keys?


Unfortunately, I get back the t/filter/ crash with this
patch ...


That just proves that the problem is unrelated to keys, but to the fact that subpools are destroyed. Both your previous patches weren't destroying either the parent or the child pools, hence you had a partial success I believe.

We are adjusting the warning in userdata_set docco to disambiguate the note and tell that the uniqueness is needed only inside the same pool, not even a pool and its sub-pool. it's just that each pool uses its own apr_hash_t to store the keys and the data, that's why uniqueness is needed.

Stas, In the light of Randy's response I haven't tried out your patch above. Do you still want me to or not?




Back to the sketching board. It took me half a day of apr patching to just be able to debug with --enable-pool-debug=all, which didn't quite work out of box :( I wish I had the segfault like you do, it'd make my debugging so much easier, rather than looking at the addresses and trying to figure out what could go wrong when everything seems to be OK.

BTW, does apr pool debugging work for you? Please try building apr as:

cd httpd-2.0/srclib/apr>
make distclean
./configure --enable-pool-debug=all --enable-maintainer-mode --prefix=/home/stas/httpd/prefork && make
make install


of course adjust the prefix ;)

I'm trying to turn on the apr pool debugging, but without much success. The build process on Win32 is completely different. The httpd .tar.gz file sources don't build at all on Win32 -- we have to use the win32-src.zip file sources instead. This includes various windows makefiles, including apr.mak and libapr.mak in the srclib/apr directory. I've hacked both of them to add /DAPR_POOL_DEBUG=31 into the CPP_PROJ macros; that seems to be what --enable-pool-debug=all would have done. Is that all I need to do?


I then rebuilt Apache2 & mp2, but then couldn't even start the server. (It emits mountains of crap into the console window when trying, though! Lines like this:

POOL DEBUG: [2692/52] PCALLOC ( 429808/ 430630/ 436490) 0x00285A88 "pconf" <.\tables\apr_tables.c:101> (8694/8694/0)

hundreds of times over. But nothing to the error_log!)



If it segfaults on start like it did for me, I have posted a workaround here:
http://marc.theaimsgroup.com/?l=apr-dev&m=106447516910813&w=2
not sure whether it will work for you, since it slashes a global pool's mutex.

I tried applying the patch you posted at the address above to fix the startup failure that I now have. I hacked apr/misc/win32/start.c rather than apr/misc/unix/start.c; that also involved copying apr_atomic_init() from elsewhere too, otherwise it was undefined!


Sadly, all my hacking has got me nowhere - I still can't start Apache2.

A complete diff of what I did to try to enable apr pool debugging is attached.

- Steve
diff -ruN httpd-2.0.47.orig/srclib/apr/apr.mak httpd-2.0.47/srclib/apr/apr.mak
--- httpd-2.0.47.orig/srclib/apr/apr.mak        2003-09-25 10:29:36.960478200 +0100
+++ httpd-2.0.47/srclib/apr/apr.mak     2003-09-25 09:45:11.800683700 +0100
@@ -106,7 +106,7 @@
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
 
 CPP=cl.exe
-CPP_PROJ=/nologo /MD /W3 /Zi /O2 /I "./include" /I "./include/arch" /I 
"./include/arch/win32" /I "./include/arch/unix" /D "NDEBUG" /D "APR_DECLARE_STATIC" /D 
"WIN32" /D "_WINDOWS" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\apr_src" /FD /c 
+CPP_PROJ=/nologo /MD /W3 /Zi /O2 /I "./include" /I "./include/arch" /I 
"./include/arch/win32" /I "./include/arch/unix" /D "NDEBUG" /D "APR_DECLARE_STATIC" /D 
"WIN32" /D "_WINDOWS" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\apr_src" /FD /c 
/DAPR_POOL_DEBUG=31
 
 .c{$(INTDIR)}.obj::
    $(CPP) @<<
@@ -295,7 +295,7 @@
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
 
 CPP=cl.exe
-CPP_PROJ=/nologo /MDd /W3 /GX /Zi /Od /I "./include" /I "./include/arch" /I 
"./include/arch/win32" /I "./include/arch/unix" /D "_DEBUG" /D "APR_DECLARE_STATIC" /D 
"WIN32" /D "_WINDOWS" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\apr_src" /FD /c 
+CPP_PROJ=/nologo /MDd /W3 /GX /Zi /Od /I "./include" /I "./include/arch" /I 
"./include/arch/win32" /I "./include/arch/unix" /D "_DEBUG" /D "APR_DECLARE_STATIC" /D 
"WIN32" /D "_WINDOWS" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\apr_src" /FD /c 
/DAPR_POOL_DEBUG=31
 
 .c{$(INTDIR)}.obj::
    $(CPP) @<<
diff -ruN httpd-2.0.47.orig/srclib/apr/libapr.mak httpd-2.0.47/srclib/apr/libapr.mak
--- httpd-2.0.47.orig/srclib/apr/libapr.mak     2003-09-25 10:29:42.085412600 +0100
+++ httpd-2.0.47/srclib/apr/libapr.mak  2003-09-25 09:45:00.472703700 +0100
@@ -110,7 +110,7 @@
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
 
 CPP=cl.exe
-CPP_PROJ=/nologo /MD /W3 /Zi /O2 /I "./include" /I "./include/arch" /I 
"./include/arch/win32" /I "./include/arch/unix" /D "NDEBUG" /D "APR_DECLARE_EXPORT" /D 
"WIN32" /D "_WINDOWS" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\libapr_src" /FD /c 
+CPP_PROJ=/nologo /MD /W3 /Zi /O2 /I "./include" /I "./include/arch" /I 
"./include/arch/win32" /I "./include/arch/unix" /D "NDEBUG" /D "APR_DECLARE_EXPORT" /D 
"WIN32" /D "_WINDOWS" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\libapr_src" /FD /c 
/DAPR_POOL_DEBUG=31
 
 .c{$(INTDIR)}.obj::
    $(CPP) @<<
@@ -307,7 +307,7 @@
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
 
 CPP=cl.exe
-CPP_PROJ=/nologo /MDd /W3 /GX /Zi /Od /I "./include" /I "./include/arch" /I 
"./include/arch/win32" /I "./include/arch/unix" /D "_DEBUG" /D "APR_DECLARE_EXPORT" /D 
"WIN32" /D "_WINDOWS" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\libapr_src" /FD /c 
+CPP_PROJ=/nologo /MDd /W3 /GX /Zi /Od /I "./include" /I "./include/arch" /I 
"./include/arch/win32" /I "./include/arch/unix" /D "_DEBUG" /D "APR_DECLARE_EXPORT" /D 
"WIN32" /D "_WINDOWS" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\libapr_src" /FD /c 
/DAPR_POOL_DEBUG=31
 
 .c{$(INTDIR)}.obj::
    $(CPP) @<<
diff -ruN httpd-2.0.47.orig/srclib/apr/memory/unix/apr_pools.c 
httpd-2.0.47/srclib/apr/memory/unix/apr_pools.c
--- httpd-2.0.47.orig/srclib/apr/memory/unix/apr_pools.c        2003-05-27 
21:39:42.000000000 +0100
+++ httpd-2.0.47/srclib/apr/memory/unix/apr_pools.c     2003-09-25 10:07:45.898861200 
+0100
@@ -1505,6 +1505,12 @@
 {
     apr_pool_t *pool;
 
+    if (allocator == (apr_allocator_t *)0xdeadbeaf) {
+        allocator = NULL;
+        global_pool->mutex = NULL;
+
+    }
+
     *newpool = NULL;
 
     if (!parent) {
diff -ruN httpd-2.0.47.orig/srclib/apr/misc/win32/start.c 
httpd-2.0.47/srclib/apr/misc/win32/start.c
--- httpd-2.0.47.orig/srclib/apr/misc/win32/start.c     2003-01-06 15:52:56.000000000 
+0000
+++ httpd-2.0.47/srclib/apr/misc/win32/start.c  2003-09-25 10:12:25.128547200 +0100
@@ -198,6 +198,31 @@
 /* Provide to win32/thread.c */
 extern DWORD tls_apr_thread;
 
+#if APR_HAS_THREADS
+#define NUM_ATOMIC_HASH 7
+/* shift by 2 to get rid of alignment issues */
+#define ATOMIC_HASH(x) (unsigned int)(((unsigned long)(x)>>2)%(unsigned 
int)NUM_ATOMIC_HASH)
+static apr_thread_mutex_t **hash_mutex;
+#endif /* APR_HAS_THREADS */
+
+apr_status_t apr_atomic_init(apr_pool_t *p)
+{
+#if APR_HAS_THREADS
+    int i;
+    apr_status_t rv;
+    hash_mutex = apr_palloc(p, sizeof(apr_thread_mutex_t*) * NUM_ATOMIC_HASH);
+
+    for (i = 0; i < NUM_ATOMIC_HASH; i++) {
+        rv = apr_thread_mutex_create(&(hash_mutex[i]),
+                                     APR_THREAD_MUTEX_DEFAULT, p);
+        if (rv != APR_SUCCESS) {
+           return rv;
+        }
+    }
+#endif /* APR_HAS_THREADS */
+    return APR_SUCCESS;
+}
+
 APR_DECLARE(apr_status_t) apr_initialize(void)
 {
     apr_pool_t *pool;
@@ -219,7 +244,24 @@
     tls_apr_thread = TlsAlloc();
     if ((status = apr_pool_initialize()) != APR_SUCCESS)
         return status;
-    
+
+#if APR_POOL_DEBUG
+    {
+        apr_pool_t *pool = NULL;
+        apr_status_t rv;
+
+        if ((rv = apr_pool_create_ex(&pool, NULL, NULL,
+                                     (apr_allocator_t *)0xdeadbeaf)
+                ) != APR_SUCCESS) {
+            return rv;
+        }
+
+        if ((status = apr_atomic_init(pool)) != APR_SUCCESS) {
+            return status;
+        }
+    }
+#endif
+   
     if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
         return APR_ENOPOOL;
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to