From 134950dc97803dec941651fc12063cc630f609f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Thu, 21 Nov 2024 10:03:35 +0100 Subject: [PATCH] Fix missing locking when using mod_proxy_balancer ref #235 --- native/balancers/mod_lbmethod_cluster.c | 4 ++++ native/mod_manager/mod_manager.c | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/native/balancers/mod_lbmethod_cluster.c b/native/balancers/mod_lbmethod_cluster.c index 25327378..bda7ab36 100644 --- a/native/balancers/mod_lbmethod_cluster.c +++ b/native/balancers/mod_lbmethod_cluster.c @@ -93,7 +93,9 @@ static proxy_worker *find_best(proxy_balancer *balancer, request_rec *r) node_table = read_node_table(r->pool, node_storage, 0); } + node_storage->lock_nodes(); mycandidate = internal_find_best_byrequests(r, balancer, vhost_table, context_table, node_table); + node_storage->unlock_nodes(); return mycandidate; } @@ -321,7 +323,9 @@ static apr_status_t mc_watchdog_callback(int state, void *data, apr_pool_t *pool } /* cleanup removed node in shared memory */ + node_storage->lock_nodes(); remove_removed_node(s, pool, now, node_table); + node_storage->unlock_nodes(); } break; diff --git a/native/mod_manager/mod_manager.c b/native/mod_manager/mod_manager.c index b6837deb..a391f939 100644 --- a/native/mod_manager/mod_manager.c +++ b/native/mod_manager/mod_manager.c @@ -935,7 +935,10 @@ static apr_status_t mod_manager_manage_worker(request_rec *r, const nodeinfo_t * apr_table_set(params, "b_wyes", "1"); apr_table_set(params, "b_nwrkr", apr_pstrcat(r->pool, node->mess.Type, "://", node->mess.Host, ":", node->mess.Port, NULL)); - balancer_manage(r, params); + rv = balancer_manage(r, params); + if (rv != APR_SUCCESS) { + return rv; + } apr_table_clear(params); /* now process the worker */ @@ -1572,7 +1575,6 @@ static char *process_config(request_rec *r, char **ptr, int *errtype) /* Insert the Alias and corresponding Context */ phost = vhost; if (phost->host == NULL && phost->context == NULL) { - loc_unlock_nodes(); /* if using mod_balancer create or update the worker */ if (balancer_manage) { apr_status_t rv = mod_manager_manage_worker(r, &nodeinfo, &balancerinfo); @@ -1580,6 +1582,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype) } else { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "process_config: NO balancer-manager"); } + loc_unlock_nodes(); return NULL; /* Alias and Context missing */ } while (phost) { @@ -1594,7 +1597,6 @@ static char *process_config(request_rec *r, char **ptr, int *errtype) phost = phost->next; vid++; } - loc_unlock_nodes(); /* if using mod_balancer create or update the worker */ if (balancer_manage) { @@ -1603,6 +1605,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype) } else { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "process_config: NO balancer-manager"); } + loc_unlock_nodes(); ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "process_config: Done");