From: Mladen Turk Date: Fri, 10 Sep 2004 18:29:16 +0000 (+0000) Subject: Just like for balancers initialize the workers on post_config X-Git-Tag: 2.1.1~308 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=225dd230c43650728af963efa7ca7bd347bb6b93;p=apache Just like for balancers initialize the workers on post_config instead on first request to skip the race condition. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@105064 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index ac9622390b..e8c8e7081f 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -1349,7 +1349,6 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg) } /* Add the worker to the load balancer */ ap_proxy_add_worker_to_balancer(cmd->pool, balancer, worker); - return NULL; } @@ -1596,9 +1595,21 @@ PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c) static int proxy_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { + proxy_server_conf *conf = + (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module); + proxy_worker *worker; + int i; + proxy_ssl_enable = APR_RETRIEVE_OPTIONAL_FN(ssl_proxy_enable); proxy_ssl_disable = APR_RETRIEVE_OPTIONAL_FN(ssl_engine_disable); + /* Initialize all the workers */ + worker = (proxy_worker *)conf->workers->elts; + for (i = 0; i < conf->workers->nelts; i++) { + ap_proxy_initialize_worker(worker, s); + worker++; + } + return OK; } diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 17fe6d0bfc..f2ebe9adc9 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -282,7 +282,6 @@ typedef struct { } proxy_runtime_worker; struct proxy_balancer { - int status; apr_array_header_t *workers; /* array of proxy_runtime_workers */ const char *name; /* name of the load balancer */ const char *sticky; /* sticky session identifier */ @@ -409,6 +408,16 @@ PROXY_DECLARE(const char *) ap_proxy_add_worker(proxy_worker **worker, apr_pool_t *p, proxy_server_conf *conf, const char *url); + +/** + * Initize the worker + * @param worker the new worker + * @param p memory pool to allocate worker from + * @param s current server record + * @return APR_SUCCESS or error code + */ +PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, + server_rec *s); /** * Get the balancer from proxy configuration * @param p memory pool used for finding balancer diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 8d09132fe7..607f08df72 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1377,7 +1377,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_close_connection(proxy_conn_rec *conn) return connection_destructor(conn, NULL, NULL); } -static apr_status_t init_conn_worker(proxy_worker *worker, server_rec *s) +PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, server_rec *s) { apr_status_t rv; @@ -1420,13 +1420,13 @@ static apr_status_t init_conn_worker(proxy_worker *worker, server_rec *s) #endif { - connection_constructor((void **)&(worker->cp->conn), s, worker->cp->pool); - rv = APR_SUCCESS; + rv = connection_constructor((void **)&(worker->cp->conn), s, worker->cp->pool); ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "proxy: initialized single connection worker for (%s)", worker->hostname); } - + if (rv == APR_SUCCESS) + worker->status |= PROXY_WORKER_INITIALIZED; return rv; } @@ -1465,16 +1465,6 @@ PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function, { apr_status_t rv; - if (!(worker->status & PROXY_WORKER_INITIALIZED)) { - if ((rv = init_conn_worker(worker, s)) != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, - "proxy: %s: failed to initialize worker for (%s)", - proxy_function, worker->hostname); - return HTTP_INTERNAL_SERVER_ERROR; - } - worker->status |= PROXY_WORKER_INITIALIZED; - } - if (!PROXY_WORKER_IS_USABLE(worker)) { /* Retry the worker */ ap_proxy_retry_worker(proxy_function, worker, s);