https://issues.apache.org/bugzilla/show_bug.cgi?id=49504

--- Comment #10 from Yann Ylavic <[email protected]> ---
(In reply to Jim Jagielski from comment #9)
> A non-leaking patch should be relatively easy to create...

I don't find it so easy because we have to wait for all the children using the
mutex to exit before we can pthread_mutex_destroy() it (so to avoid the
corruption of the shared-mmap()ing while the children are sill running).

For graceful restarts, this may happen long after the parent has reloaded the
new configuration, hence created/destroyed the new/unused-old mutexes.

We could use a refcounter, incremented whenever a child is created, decremented
when it exits, and then destroy the mutex only when the counter reaches 0 (the
parent process would hold its own reference until the mutex is not configured
anymore to avoid some race conditions).
But this seems to require a synchronisation which does not exist yet in httpd
(between the mpm creating the child and perform_idle_server_maintenance() where
the child exit is taken into account?).

Another possibility would be to include this refcounter into the mmap()ing (eg.
sizeof(refcounter_t) + sizeof(pthread_mutex_t)), and then increment in
proc_mutex_proc_pthread_create() AND proc_mutex_proc_pthread_child_init()
(which is proc_mutex_no_child_init() for now). To decrement the refcounter,
apr_proc_mutex_child_init() would register a cleanup on its given pool (pchild)
which should be destroyed/cleared upon exit (mpm's clean_child_exit() does
destroy pchild).
However that won't work with [seg]faulting children (they don't destroy
pchild), so the refcounter may still be wrong and the mutex still leak...

Yet another possibility would be to not call pthread_mutex_destroy() in
proc_mutex_proc_pthread_cleanup(), only munmap()ing the region (the mmap()ing
would still be valid for all the fork()ed children until all of them exit).
This shouldn't hurt since (AFAICT) pthread_mutex_t does not hold system
resources, otherwise "mutex = PTHREAD_MUTEX_INITIALIZER;" could not be used to
initialize a mutex instead of pthread_mutex_init().
So the only leek to care about when cleaning up is probably the mmap()ing.

The last two proposals are APR things though, not httpd.

I guess I'm missing an obvious solution...

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to