Skip to content

Commit 8d956d1

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 82b5064 commit 8d956d1

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
@@ -992,12 +992,32 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
992992
sctx_t *ctx = (sctx_t *)data;
993993
server_rec *s = ctx->s;
994994
proxy_server_conf *conf;
995+
proxy_worker **workers;
996+
proxy_worker *worker;
997+
apr_time_t now;
998+
int i, n;
999+
1000+
conf = ap_get_module_config(s->module_config, &proxy_module);
9951001

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

10241044
case AP_WATCHDOG_STATE_RUNNING:
10251045
/* loop thru all workers */
1026-
if (s) {
1027-
int i;
1028-
conf = (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
1046+
{
10291047
balancer = (proxy_balancer *)conf->balancers->elts;
1030-
ctx->s = s;
10311048
for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
1032-
int n;
1033-
apr_time_t now;
1034-
proxy_worker **workers;
1035-
proxy_worker *worker;
10361049
/* Have any new balancers or workers been added dynamically? */
10371050
ap_proxy_sync_balancer(balancer, s, conf);
1038-
workers = (proxy_worker **)balancer->workers->elts;
1051+
10391052
now = apr_time_now();
1040-
for (n = 0; n < balancer->workers->nelts; n++) {
1053+
workers = (proxy_worker **)balancer->workers->elts;
1054+
for (n = 0; n < balancer->workers->nelts; n++, workers++) {
10411055
worker = *workers;
10421056
if (!PROXY_WORKER_IS(worker, PROXY_WORKER_STOPPED) &&
10431057
(worker->s->method != NONE) &&
1044-
(worker->s->updated != 0) &&
1045-
(now > worker->s->updated + worker->s->interval)) {
1058+
(now > worker->s->updated + worker->s->interval) &&
1059+
(worker->s->updated != 0)) {
10461060
baton_t *baton;
10471061
apr_pool_t *ptemp;
10481062

1063+
/* Zero to prevent concurrent checks for the same worker,
1064+
* should a check take longer than the watchdog interval.
1065+
*/
1066+
worker->s->updated = 0;
1067+
10491068
ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, s,
10501069
"Checking %s worker: %s [%d] (%pp)", balancer->s->name,
10511070
worker->s->name_ex, worker->s->method, worker);
@@ -1063,7 +1082,7 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
10631082
apr_pool_destroy(ptemp);
10641083
return rv;
10651084
}
1066-
worker->s->updated = 0;
1085+
10671086
#if HC_USE_THREADS
10681087
if (hctp) {
10691088
apr_thread_pool_push(hctp, hc_check, (void *)baton,
@@ -1077,7 +1096,6 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
10771096
hc_check(NULL, baton);
10781097
}
10791098
}
1080-
workers++;
10811099
}
10821100
}
10831101
}

0 commit comments

Comments
 (0)