From: Stefan Eissing Date: Thu, 24 Feb 2022 11:53:53 +0000 (+0000) Subject: * core/mpm: add hook 'child_stopped` that gets called when the MPM has X-Git-Tag: 2.5.0-alpha2-ci-test-only~477 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e239ed8e65a0a7cc5f12d64b4d21cc92ab08709;p=thirdparty%2Fapache%2Fhttpd.git * core/mpm: add hook 'child_stopped` that gets called when the MPM has stopped all processing in a child process. This is when all running threads shall be stopped and joined. [Stefan Eissing] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1898369 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/changes-entries/mpm_child_stopped.txt b/changes-entries/mpm_child_stopped.txt new file mode 100644 index 00000000000..7bc8bb1ec40 --- /dev/null +++ b/changes-entries/mpm_child_stopped.txt @@ -0,0 +1,5 @@ + * core/mpm: add hook 'child_stopped` that gets called when the MPM has + stopped all processing in a child process. This is when all running + threads shall be stopped and joined. + [Stefan Eissing] + diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 4fda68b1b32..84c566e0f0d 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -700,6 +700,8 @@ * add PROXY_WORKER_UDS_PATH_SIZE. * 20211221.3 (2.5.1-dev) Add ap_thread_create(), ap_thread_main_create() * and ap_thread_current() + * 20211221.4 (2.5.1-dev) Add hook child_stopped to get informed that a child + * has stopped processing any requests. * */ @@ -708,7 +710,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20211221 #endif -#define MODULE_MAGIC_NUMBER_MINOR 3 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 4 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/mpm_common.h b/include/mpm_common.h index 007a24a498e..334624ee065 100644 --- a/include/mpm_common.h +++ b/include/mpm_common.h @@ -512,14 +512,30 @@ AP_DECLARE_HOOK(void, resume_connection, (conn_rec *c, request_rec *r)) /** - * Notification that the child is stopping. If graceful, ongoing - * requests will be served. + * Notification that the child is stopping. No new requests + * or other tasks to be started. + * If graceful, already started requests/tasks should be + * processed normally. * @param pchild The child pool * @param graceful != 0 iff this is a graceful shutdown. */ AP_DECLARE_HOOK(void, child_stopping, (apr_pool_t *pchild, int graceful)) +/** + * Notification that the child has stopped processing + * requests completely. Any running threads should be + * shut down now. + * Ideally, when this hook completes, no more threads + * are running in the child process. + * Note that de-allocation of global resources should + * be run via memory pool destroy callback after this. + * @param pchild The child pool + * @param graceful != 0 iff this is a graceful shutdown. + */ +AP_DECLARE_HOOK(void, child_stopped, + (apr_pool_t *pchild, int graceful)) + /* mutex type string for accept mutex, if any; MPMs should use the * same mutex type for ease of configuration */ diff --git a/server/mpm/event/event.c b/server/mpm/event/event.c index 9e0eeca0fbb..b9f8e73c488 100644 --- a/server/mpm/event/event.c +++ b/server/mpm/event/event.c @@ -775,6 +775,7 @@ static void clean_child_exit(int code) } if (pchild) { + ap_run_child_stopped(pchild, terminate_mode == ST_GRACEFUL); apr_pool_destroy(pchild); } diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 9679d640688..d1e17b26f09 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -230,6 +230,7 @@ static void clean_child_exit(int code) } if (pchild) { + ap_run_child_stopped(pchild, 0); apr_pool_destroy(pchild); /* * Be safe in case someone still uses afterwards or we get here again. diff --git a/server/mpm/winnt/child.c b/server/mpm/winnt/child.c index ae69f833042..9b70d721b1f 100644 --- a/server/mpm/winnt/child.c +++ b/server/mpm/winnt/child.c @@ -1262,6 +1262,8 @@ void child_main(apr_pool_t *pconf, DWORD parent_pid) ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, APLOGNO(00364) "Child: All worker threads have exited."); + ap_run_child_stopped(pchild, graceful_shutdown); + apr_thread_mutex_destroy(child_lock); apr_thread_mutex_destroy(ctxpool_lock); CloseHandle(ctxpool_wait_event); diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index ed326a13672..9f05dbb8196 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -443,6 +443,7 @@ static void clean_child_exit(int code) } if (pchild) { + ap_run_child_stopped(pchild, terminate_mode == ST_GRACEFUL); apr_pool_destroy(pchild); } diff --git a/server/mpm_common.c b/server/mpm_common.c index 4b8c41e67cb..b2dac2fe49a 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -78,7 +78,8 @@ APR_HOOK_LINK(input_pending) \ APR_HOOK_LINK(suspend_connection) \ APR_HOOK_LINK(resume_connection) \ - APR_HOOK_LINK(child_stopping) + APR_HOOK_LINK(child_stopping) \ + APR_HOOK_LINK(child_stopped) #if AP_ENABLE_EXCEPTION_HOOK APR_HOOK_STRUCT( @@ -140,6 +141,9 @@ AP_IMPLEMENT_HOOK_VOID(resume_connection, AP_IMPLEMENT_HOOK_VOID(child_stopping, (apr_pool_t *pchild, int graceful), (pchild, graceful)) +AP_IMPLEMENT_HOOK_VOID(child_stopped, + (apr_pool_t *pchild, int graceful), + (pchild, graceful)) /* hooks with no args are implemented last, after disabling APR hook probes */ #if defined(APR_HOOK_PROBES_ENABLED)