]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
* core/mpm: add hook 'child_stopped` that gets called when the MPM has
authorStefan Eissing <icing@apache.org>
Thu, 24 Feb 2022 11:53:53 +0000 (11:53 +0000)
committerStefan Eissing <icing@apache.org>
Thu, 24 Feb 2022 11:53:53 +0000 (11:53 +0000)
    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

changes-entries/mpm_child_stopped.txt [new file with mode: 0644]
include/ap_mmn.h
include/mpm_common.h
server/mpm/event/event.c
server/mpm/prefork/prefork.c
server/mpm/winnt/child.c
server/mpm/worker/worker.c
server/mpm_common.c

diff --git a/changes-entries/mpm_child_stopped.txt b/changes-entries/mpm_child_stopped.txt
new file mode 100644 (file)
index 0000000..7bc8bb1
--- /dev/null
@@ -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]
+
index 4fda68b1b32faf44641a1e71e438c4f59e432dab..84c566e0f0dac43c132571f67c485fef62f968e3 100644 (file)
  *                         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.
  *
  */
 
 #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
index 007a24a498edb496a74a7ea41f9e888cc27a6dda..334624ee065a84721f2da7a804defd10c9f15882 100644 (file)
@@ -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
  */
index 9e0eeca0fbbd3657fc32a11033b7540a5ffe21a3..b9f8e73c4887de0b0f9c4955b76e6516e3fc6a1b 100644 (file)
@@ -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);
     }
 
index 9679d6406886f81a040ec5ecbf828f28ba833a79..d1e17b26f09137b317ad2a199c3a1a181130bb6e 100644 (file)
@@ -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.
index ae69f83304288807bf709efb48f90276fd5af51b..9b70d721b1f415beab71282804aedb76120df8b0 100644 (file)
@@ -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);
index ed326a13672b20e61d5a0902796fe97cca32b5ea..9f05dbb81967e97800c106aa78c24d505c448791 100644 (file)
@@ -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);
     }
 
index 4b8c41e67cb0fdecef5a58a33888d185d4a8c1f2..b2dac2fe49ad5f71482155cd1d4016f8027485fa 100644 (file)
@@ -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)