From 564ed2c86a2e31aac2fac6a7006d9c36f1ae92a5 Mon Sep 17 00:00:00 2001 From: Justin Erenkrantz Date: Wed, 1 May 2002 07:15:39 +0000 Subject: [PATCH] Close sockets on worker MPM when doing a graceless restart. This should resolve some segfaults see when doing such restarts. (Justin tweaked the palloc/memset in favor of calloc.) Submitted by: Aaron Bannert Reviewed by: Greg Ames, Sander Striker, Justin Erenkrantz git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@94886 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ server/mpm/worker/worker.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGES b/CHANGES index b6a954bbbf..9f2357a2e8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ Changes with Apache 2.0.37 + *) Close sockets on worker MPM when doing a graceless restart. + [Aaron Bannert] + *) Reverted a minor optimization in mod_ssl.c that used the vhost ID as the session id context rather that a MD5 hash of that vhost ID, because it caused very long vhost id's to be unusable with mod_ssl. diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 40b6bc9ff9..6564384861 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -252,6 +252,21 @@ static apr_proc_mutex_t *accept_mutex; */ #define LISTENER_SIGNAL SIGHUP +/* An array of socket descriptors in use by each thread used to + * perform a non-graceful (forced) shutdown of the server. */ +static apr_socket_t **worker_sockets; + +static void close_worker_sockets(void) +{ + int i; + for (i = 0; i < ap_threads_per_child; i++) { + if (worker_sockets[i]) { + apr_socket_close(worker_sockets[i]); + worker_sockets[i] = NULL; + } + } +} + static void wakeup_listener(void) { listener_may_exit = 1; @@ -301,6 +316,7 @@ static void signal_threads(int mode) workers_may_exit = 1; ap_queue_interrupt_all(worker_queue); ap_queue_info_term(worker_queue_info); + close_worker_sockets(); /* forcefully kill all current connections */ } } @@ -912,7 +928,9 @@ worker_pop: } continue; } + worker_sockets[thread_slot] = csd; process_socket(ptrans, csd, process_slot, thread_slot, bucket_alloc); + worker_sockets[thread_slot] = NULL; requests_this_child--; /* FIXME: should be synchronized - aaron */ apr_pool_clear(ptrans); last_ptrans = ptrans; @@ -1002,6 +1020,9 @@ static void * APR_THREAD_FUNC start_threads(apr_thread_t *thd, void *dummy) clean_child_exit(APEXIT_CHILDFATAL); } + worker_sockets = apr_pcalloc(pchild, ap_threads_per_child + * sizeof(apr_socket_t *)); + loops = prev_threads_created = 0; while (1) { /* ap_threads_per_child does not include the listener thread */ -- 2.50.1