mod_proxy_http2: thread safety with MPM prefork, still..
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.
@@ -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.
