diff options
author | Stefan Eissing <icing@apache.org> | 2022-02-24 11:56:01 +0000 |
---|---|---|
committer | Stefan Eissing <icing@apache.org> | 2022-02-24 11:56:01 +0000 |
commit | 338daf4719fe28f3d765ef92740d832ac141b742 (patch) | |
tree | e3cf7bc383e353b170d5a031b945df7532571b5f /modules/core | |
parent | 2e239ed8e65a0a7cc5f12d64b4d21cc92ab08709 (diff) | |
download | httpd-338daf4719fe28f3d765ef92740d832ac141b742.tar.gz |
*) mod_watchdog: use the `child_stopping` and `child_stopped` hooks
to shutdown workers before pool destruction releases global
resources and libraries.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1898370 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules/core')
-rw-r--r-- | modules/core/mod_watchdog.c | 61 |
1 files changed, 52 insertions, 9 deletions
diff --git a/modules/core/mod_watchdog.c b/modules/core/mod_watchdog.c index ddff36741f..fba5e87ed9 100644 --- a/modules/core/mod_watchdog.c +++ b/modules/core/mod_watchdog.c @@ -72,14 +72,11 @@ static apr_interval_time_t wd_interval = AP_WD_TM_INTERVAL; static int mpm_is_forked = AP_MPMQ_NOT_SUPPORTED; static const char *wd_proc_mutex_type = "watchdog-callback"; -static apr_status_t wd_worker_cleanup(void *data) +static void wd_worker_stop(ap_watchdog_t *w) { - apr_status_t rv; - ap_watchdog_t *w = (ap_watchdog_t *)data; - /* Do nothing if the thread wasn't started. */ if (apr_atomic_read32(&w->thread_started) != 1) - return APR_SUCCESS; + return; if (apr_atomic_read32(&w->is_running)) { watchdog_list_t *wl = w->callbacks; @@ -94,6 +91,18 @@ static apr_status_t wd_worker_cleanup(void *data) } } apr_atomic_set32(&w->is_running, 0); +} + +static apr_status_t wd_worker_cleanup(void *data) +{ + apr_status_t rv; + ap_watchdog_t *w = (ap_watchdog_t *)data; + + /* Do nothing if the thread wasn't started. */ + if (apr_atomic_read32(&w->thread_started) != 1) + return APR_SUCCESS; + + wd_worker_stop(w); apr_thread_join(&rv, w->thread); return rv; } @@ -561,7 +570,7 @@ static void wd_child_init_hook(apr_pool_t *p, server_rec *s) /*--------------------------------------------------------------------------*/ /* */ /* Child stopping hook. */ -/* Shutdown watchdog threads */ +/* Do not run new watchdog tasks. */ /* */ /*--------------------------------------------------------------------------*/ static void wd_child_stopping(apr_pool_t *pool, int graceful) @@ -581,7 +590,35 @@ static void wd_child_stopping(apr_pool_t *pool, int graceful) ap_watchdog_t *w = ap_lookup_provider(AP_WATCHDOG_PGROUP, wn[i].provider_name, AP_WATCHDOG_CVERSION); - apr_atomic_set32(&w->is_running, 0); + wd_worker_stop(w); + } + } +} + +/*--------------------------------------------------------------------------*/ +/* */ +/* Child stopped hook. */ +/* Terminate/join all watchdog threads */ +/* */ +/*--------------------------------------------------------------------------*/ +static void wd_child_stopped(apr_pool_t *pool, int graceful) +{ + const apr_array_header_t *wl; + + if (!wd_server_conf->child_workers) { + return; + } + if ((wl = ap_list_provider_names(pool, AP_WATCHDOG_PGROUP, + AP_WATCHDOG_CVERSION))) { + const ap_list_provider_names_t *wn; + int i; + + wn = (ap_list_provider_names_t *)wl->elts; + for (i = 0; i < wl->nelts; i++) { + ap_watchdog_t *w = ap_lookup_provider(AP_WATCHDOG_PGROUP, + wn[i].provider_name, + AP_WATCHDOG_CVERSION); + wd_worker_cleanup(w); } } } @@ -663,14 +700,20 @@ static void wd_register_hooks(apr_pool_t *p) NULL, APR_HOOK_MIDDLE); -#if AP_MODULE_MAGIC_AT_LEAST(20120211, 110) /* Child is stopping hook */ ap_hook_child_stopping(wd_child_stopping, NULL, NULL, APR_HOOK_MIDDLE); -#endif + + /* Child has stopped hook + */ + ap_hook_child_stopping(wd_child_stopped, + NULL, + NULL, + APR_HOOK_MIDDLE); + APR_REGISTER_OPTIONAL_FN(ap_watchdog_get_instance); APR_REGISTER_OPTIONAL_FN(ap_watchdog_register_callback); APR_REGISTER_OPTIONAL_FN(ap_watchdog_set_callback_interval); |