On Thu, 2009-10-22 at 07:54 -0400, Jeff Trawick wrote:
> I have long suspected that there is a race here, and that this code
> should do shutdown for read and write rather than close in order to
> avoid any possible funny business with descriptors.

Phew! So I'm not totally insane after all :-)

Note that the attached _still_ has a race. If worker_sockets[i] is set
to NULL by the worker (i.e. processing just finished) before we get that
csd, we are going to segfault.

Having ap_threads_per_child mutexes (i.e. one for each
worker_sockets[i]) would probably be an overkill, so if we had just one
for all worker_sockets, that would be an improvement, although it would
slow things down a little bit.

-- 
Bojan
Index: server/mpm/worker/worker.c
===================================================================
--- server/mpm/worker/worker.c	(revision 828847)
+++ server/mpm/worker/worker.c	(working copy)
@@ -239,11 +239,11 @@
 
 static void close_worker_sockets(void)
 {
-    int i;
+    int i, csd;
     for (i = 0; i < threads_per_child; i++) {
         if (worker_sockets[i]) {
-            apr_socket_close(worker_sockets[i]);
-            worker_sockets[i] = NULL;
+            apr_os_sock_get((apr_os_sock_t *)&csd, worker_sockets[j]);
+            shutdown(csd, SHUT_RDWR);
         }
     }
 }

Reply via email to