mirror of
https://github.com/apache/httpd.git
synced 2025-08-07 04:02:58 +03:00
mod_proxy: Use a global mutex for handling workers.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1482859 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -36,6 +36,9 @@ APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
|
|||||||
#define MAX(x,y) ((x) >= (y) ? (x) : (y))
|
#define MAX(x,y) ((x) >= (y) ? (x) : (y))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char * const proxy_id = "proxy";
|
||||||
|
apr_global_mutex_t *proxy_mutex = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A Web proxy module. Stages:
|
* A Web proxy module. Stages:
|
||||||
*
|
*
|
||||||
@@ -1194,9 +1197,7 @@ static void * create_proxy_config(apr_pool_t *p, server_rec *s)
|
|||||||
ps->source_address = NULL;
|
ps->source_address = NULL;
|
||||||
ps->source_address_set = 0;
|
ps->source_address_set = 0;
|
||||||
apr_pool_create_ex(&ps->pool, p, NULL, NULL);
|
apr_pool_create_ex(&ps->pool, p, NULL, NULL);
|
||||||
apr_global_mutex_create(&ps->mutex,
|
|
||||||
"mod_proxy_config_mutex",
|
|
||||||
APR_LOCK_DEFAULT, p);
|
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1258,7 +1259,6 @@ static void * merge_proxy_config(apr_pool_t *p, void *basev, void *overridesv)
|
|||||||
ps->source_address = (overrides->source_address_set == 0) ? base->source_address : overrides->source_address;
|
ps->source_address = (overrides->source_address_set == 0) ? base->source_address : overrides->source_address;
|
||||||
ps->source_address_set = overrides->source_address_set || base->source_address_set;
|
ps->source_address_set = overrides->source_address_set || base->source_address_set;
|
||||||
ps->pool = base->pool;
|
ps->pool = base->pool;
|
||||||
ps->mutex = base->mutex;
|
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
static const char *set_source_address(cmd_parms *parms, void *dummy,
|
static const char *set_source_address(cmd_parms *parms, void *dummy,
|
||||||
@@ -2405,6 +2405,13 @@ PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s,
|
|||||||
static int proxy_post_config(apr_pool_t *pconf, apr_pool_t *plog,
|
static int proxy_post_config(apr_pool_t *pconf, apr_pool_t *plog,
|
||||||
apr_pool_t *ptemp, server_rec *s)
|
apr_pool_t *ptemp, server_rec *s)
|
||||||
{
|
{
|
||||||
|
apr_status_t rv = ap_global_mutex_create(&proxy_mutex, NULL,
|
||||||
|
proxy_id, NULL, s, pconf, 0);
|
||||||
|
if (rv != APR_SUCCESS) {
|
||||||
|
ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, plog, APLOGNO()
|
||||||
|
"failed to create %s mutex", proxy_id);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
proxy_ssl_enable = APR_RETRIEVE_OPTIONAL_FN(ssl_proxy_enable);
|
proxy_ssl_enable = APR_RETRIEVE_OPTIONAL_FN(ssl_proxy_enable);
|
||||||
proxy_ssl_disable = APR_RETRIEVE_OPTIONAL_FN(ssl_engine_disable);
|
proxy_ssl_disable = APR_RETRIEVE_OPTIONAL_FN(ssl_engine_disable);
|
||||||
@@ -2564,11 +2571,19 @@ static void child_init(apr_pool_t *p, server_rec *s)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* This routine is called before the server processes the configuration
|
* This routine is called before the server processes the configuration
|
||||||
* files. There is no return value.
|
* files.
|
||||||
*/
|
*/
|
||||||
static int proxy_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
|
static int proxy_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
|
||||||
apr_pool_t *ptemp)
|
apr_pool_t *ptemp)
|
||||||
{
|
{
|
||||||
|
apr_status_t rv = ap_mutex_register(pconf, proxy_id, NULL,
|
||||||
|
APR_LOCK_DEFAULT, 0);
|
||||||
|
if (rv != APR_SUCCESS) {
|
||||||
|
ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, plog, APLOGNO()
|
||||||
|
"failed to register %s mutex", proxy_id);
|
||||||
|
return 500; /* An HTTP status would be a misnomer! */
|
||||||
|
}
|
||||||
|
|
||||||
APR_OPTIONAL_HOOK(ap, status_hook, proxy_status_hook, NULL, NULL,
|
APR_OPTIONAL_HOOK(ap, status_hook, proxy_status_hook, NULL, NULL,
|
||||||
APR_HOOK_MIDDLE);
|
APR_HOOK_MIDDLE);
|
||||||
/* Reset workers count on gracefull restart */
|
/* Reset workers count on gracefull restart */
|
||||||
|
@@ -76,6 +76,8 @@ static int lb_workers_limit = 0;
|
|||||||
const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_path;
|
const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_path;
|
||||||
const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_domain;
|
const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_domain;
|
||||||
|
|
||||||
|
extern apr_global_mutex_t *proxy_mutex;
|
||||||
|
|
||||||
static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
|
static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
|
||||||
static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
|
static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
|
||||||
static int proxy_match_hostname(struct dirconn_entry *This, request_rec *r);
|
static int proxy_match_hostname(struct dirconn_entry *This, request_rec *r);
|
||||||
@@ -1681,7 +1683,6 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
|
|||||||
{
|
{
|
||||||
apr_status_t rv = APR_SUCCESS;
|
apr_status_t rv = APR_SUCCESS;
|
||||||
int mpm_threads;
|
int mpm_threads;
|
||||||
proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(s->module_config, &proxy_module);
|
|
||||||
|
|
||||||
if (worker->s->status & PROXY_WORKER_INITIALIZED) {
|
if (worker->s->status & PROXY_WORKER_INITIALIZED) {
|
||||||
/* The worker is already initialized */
|
/* The worker is already initialized */
|
||||||
@@ -1731,14 +1732,14 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
|
|||||||
else {
|
else {
|
||||||
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00927)
|
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00927)
|
||||||
"initializing worker %s local", worker->s->name);
|
"initializing worker %s local", worker->s->name);
|
||||||
apr_global_mutex_lock(conf->mutex);
|
apr_global_mutex_lock(proxy_mutex);
|
||||||
/* Now init local worker data */
|
/* Now init local worker data */
|
||||||
if (worker->tmutex == NULL) {
|
if (worker->tmutex == NULL) {
|
||||||
rv = apr_thread_mutex_create(&(worker->tmutex), APR_THREAD_MUTEX_DEFAULT, p);
|
rv = apr_thread_mutex_create(&(worker->tmutex), APR_THREAD_MUTEX_DEFAULT, p);
|
||||||
if (rv != APR_SUCCESS) {
|
if (rv != APR_SUCCESS) {
|
||||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00928)
|
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00928)
|
||||||
"can not create worker thread mutex");
|
"can not create worker thread mutex");
|
||||||
apr_global_mutex_unlock(conf->mutex);
|
apr_global_mutex_unlock(proxy_mutex);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1747,7 +1748,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
|
|||||||
if (worker->cp == NULL) {
|
if (worker->cp == NULL) {
|
||||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00929)
|
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00929)
|
||||||
"can not create connection pool");
|
"can not create connection pool");
|
||||||
apr_global_mutex_unlock(conf->mutex);
|
apr_global_mutex_unlock(proxy_mutex);
|
||||||
return APR_EGENERAL;
|
return APR_EGENERAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1783,7 +1784,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
|
|||||||
"initialized single connection worker in child %" APR_PID_T_FMT " for (%s)",
|
"initialized single connection worker in child %" APR_PID_T_FMT " for (%s)",
|
||||||
getpid(), worker->s->hostname);
|
getpid(), worker->s->hostname);
|
||||||
}
|
}
|
||||||
apr_global_mutex_unlock(conf->mutex);
|
apr_global_mutex_unlock(proxy_mutex);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (rv == APR_SUCCESS) {
|
if (rv == APR_SUCCESS) {
|
||||||
|
Reference in New Issue
Block a user