From: Justin Erenkrantz Date: Wed, 1 May 2002 07:15:39 +0000 (+0000) Subject: Close sockets on worker MPM when doing a graceless restart. This should X-Git-Tag: 2.0.36~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fb484861e66d8254f442805352f2269f5eb9571;p=thirdparty%2Fapache%2Fhttpd.git 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 --- diff --git a/CHANGES b/CHANGES index b6a954bbbf7..9f2357a2e82 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 40b6bc9ff9d..65643848617 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 */