From: Yann Ylavic Date: Sat, 21 Nov 2020 23:23:04 +0000 (+0000) Subject: mod_proxy_http2: thread safety with MPM prefork, still.. X-Git-Tag: 2.5.0-alpha2-ci-test-only~1137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c49dadf6a2ba36f60769f729e4843e2e433b06b7;p=thirdparty%2Fapache%2Fhttpd.git 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. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1883704 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/http2/mod_http2.c b/modules/http2/mod_http2.c index 9f087ab6d68..7da3d8e128c 100644 --- a/modules/http2/mod_http2.c +++ b/modules/http2/mod_http2.c @@ -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.