]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_proxy_http2: thread safety with MPM prefork, still..
authorYann Ylavic <ylavic@apache.org>
Sat, 21 Nov 2020 23:23:04 +0000 (23:23 +0000)
committerYann Ylavic <ylavic@apache.org>
Sat, 21 Nov 2020 23:23:04 +0000 (23:23 +0000)
The allocator of pchild has no mutex with MPM prefork, but we need one
for h2 workers threads synchronization.

Even though mod_http2 shouldn't be used with prefork, better be safe than
sorry, so forcibly set the mutex in h2_child_init() if it doesn't exist.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1883704 13f79535-47bb-0310-9956-ffa450edef68

modules/http2/mod_http2.c

index 9f087ab6d68d899c6549d357dcab57a700ad5bd8..7da3d8e128c8aed5192da39f44ad42d36ac03d3e 100644 (file)
@@ -180,15 +180,30 @@ static void http2_get_num_workers(server_rec *s, int *minw, int *maxw)
 /* Runs once per created child process. Perform any process 
  * related initionalization here.
  */
-static void h2_child_init(apr_pool_t *pool, server_rec *s)
+static void h2_child_init(apr_pool_t *pchild, server_rec *s)
 {
+    apr_allocator_t *allocator;
+    apr_thread_mutex_t *mutex;
+    apr_status_t status;
+
+    /* The allocator of pchild has no mutex with MPM prefork, but we need one
+     * for h2 workers threads synchronization. Even though mod_http2 shouldn't
+     * be used with prefork, better be safe than sorry, so forcibly set the
+     * mutex here.
+     */
+    allocator = apr_pool_allocator_get(pchild);
+    mutex = apr_allocator_mutex_get(allocator);
+    if (!mutex) {
+        apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pchild);
+        apr_allocator_mutex_set(allocator, mutex);
+    }
+
     /* Set up our connection processing */
-    apr_status_t status = h2_conn_child_init(pool, s);
+    status = h2_conn_child_init(pchild, s);
     if (status != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_ERR, status, s,
                      APLOGNO(02949) "initializing connection handling");
     }
-    
 }
 
 /* Install this module into the apache2 infrastructure.