You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ic...@apache.org on 2022/02/24 11:56:01 UTC
svn commit: r1898370 - in /httpd/httpd/trunk: changes-entries/watchdog_stopped.txt modules/core/mod_watchdog.c
Author: icing
Date: Thu Feb 24 11:56:01 2022
New Revision: 1898370
URL: http://svn.apache.org/viewvc?rev=1898370&view=rev
Log:
*) mod_watchdog: use the `child_stopping` and `child_stopped` hooks
to shutdown workers before pool destruction releases global
resources and libraries.
Added:
httpd/httpd/trunk/changes-entries/watchdog_stopped.txt
Modified:
httpd/httpd/trunk/modules/core/mod_watchdog.c
Added: httpd/httpd/trunk/changes-entries/watchdog_stopped.txt
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/changes-entries/watchdog_stopped.txt?rev=1898370&view=auto
==============================================================================
--- httpd/httpd/trunk/changes-entries/watchdog_stopped.txt (added)
+++ httpd/httpd/trunk/changes-entries/watchdog_stopped.txt Thu Feb 24 11:56:01 2022
@@ -0,0 +1,4 @@
+ *) mod_watchdog: use the `child_stopping` and `child_stopped` hooks
+ to shutdown workers before pool destruction releases global
+ resources and libraries.
+ [Stefan Eissing]
\ No newline at end of file
Modified: httpd/httpd/trunk/modules/core/mod_watchdog.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/core/mod_watchdog.c?rev=1898370&r1=1898369&r2=1898370&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/core/mod_watchdog.c (original)
+++ httpd/httpd/trunk/modules/core/mod_watchdog.c Thu Feb 24 11:56:01 2022
@@ -72,14 +72,11 @@ static apr_interval_time_t wd_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(vo
}
}
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_
/*--------------------------------------------------------------------------*/
/* */
/* 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
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
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);