Skip to content

Commit e0e2757

Browse files
committed
mod_proxy_hcheck: Fix healthcheck disabled due to child restart while updating
When a child gets restarted while the healthcheck watchdog running for a worker, the healcheck will be disabled for that worker indefinitively because its ->updated time remains zero. Fix all zero ->updated time at startup. * mod_proxy_hcheck.c(hc_watchdog_callback): Have AP_WATCHDOG_STATE_STARTING set the ->updated time of all the workers to "now" (if zero). Move up scoped variables common to AP_WATCHDOG_STATE_{STARTING,RUNNING} loops. Reported by: Lubos Uhliarik <luhliari redhat.com> git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1929972 13f79535-47bb-0310-9956-ffa450edef68
1 parent d7dec4f commit e0e2757

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

modules/proxy/mod_proxy_hcheck.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -989,12 +989,32 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
989989
sctx_t *ctx = (sctx_t *)data;
990990
server_rec *s = ctx->s;
991991
proxy_server_conf *conf;
992+
proxy_worker **workers;
993+
proxy_worker *worker;
994+
apr_time_t now;
995+
int i, n;
996+
997+
conf = ap_get_module_config(s->module_config, &proxy_module);
992998

993999
switch (state) {
9941000
case AP_WATCHDOG_STATE_STARTING:
9951001
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(03258)
9961002
"%s watchdog started.",
9971003
HCHECK_WATHCHDOG_NAME);
1004+
/* If a child exits while running an hcheck the ->updated time will
1005+
* be zero, preventing further hcheck for the worker.
1006+
*/
1007+
now = apr_time_now();
1008+
balancer = (proxy_balancer *)conf->balancers->elts;
1009+
for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
1010+
workers = (proxy_worker **)balancer->workers->elts;
1011+
for (n = 0; n < balancer->workers->nelts; n++, workers++) {
1012+
worker = *workers;
1013+
if (worker->s->updated == 0) {
1014+
worker->s->updated = now;
1015+
}
1016+
}
1017+
}
9981018
#if HC_USE_THREADS
9991019
if (tpsize && hctp == NULL) {
10001020
rv = apr_thread_pool_create(&hctp, tpsize,
@@ -1020,29 +1040,28 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
10201040

10211041
case AP_WATCHDOG_STATE_RUNNING:
10221042
/* loop thru all workers */
1023-
if (s) {
1024-
int i;
1025-
conf = (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
1043+
{
10261044
balancer = (proxy_balancer *)conf->balancers->elts;
1027-
ctx->s = s;
10281045
for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
1029-
int n;
1030-
apr_time_t now;
1031-
proxy_worker **workers;
1032-
proxy_worker *worker;
10331046
/* Have any new balancers or workers been added dynamically? */
10341047
ap_proxy_sync_balancer(balancer, s, conf);
1035-
workers = (proxy_worker **)balancer->workers->elts;
1048+
10361049
now = apr_time_now();
1037-
for (n = 0; n < balancer->workers->nelts; n++) {
1050+
workers = (proxy_worker **)balancer->workers->elts;
1051+
for (n = 0; n < balancer->workers->nelts; n++, workers++) {
10381052
worker = *workers;
10391053
if (!PROXY_WORKER_IS(worker, PROXY_WORKER_STOPPED) &&
10401054
(worker->s->method != NONE) &&
1041-
(worker->s->updated != 0) &&
1042-
(now > worker->s->updated + worker->s->interval)) {
1055+
(now > worker->s->updated + worker->s->interval) &&
1056+
(worker->s->updated != 0)) {
10431057
baton_t *baton;
10441058
apr_pool_t *ptemp;
10451059

1060+
/* Zero to prevent concurrent checks for the same worker,
1061+
* should a check take longer than the watchdog interval.
1062+
*/
1063+
worker->s->updated = 0;
1064+
10461065
ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, s,
10471066
"Checking %s worker: %s [%d] (%pp)", balancer->s->name,
10481067
worker->s->name, worker->s->method, worker);
@@ -1060,7 +1079,7 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
10601079
apr_pool_destroy(ptemp);
10611080
return rv;
10621081
}
1063-
worker->s->updated = 0;
1082+
10641083
#if HC_USE_THREADS
10651084
if (hctp) {
10661085
apr_thread_pool_push(hctp, hc_check, (void *)baton,
@@ -1074,7 +1093,6 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
10741093
hc_check(NULL, baton);
10751094
}
10761095
}
1077-
workers++;
10781096
}
10791097
}
10801098
}

0 commit comments

Comments
 (0)