From 94b3a2b5522b395955a251fc1606c36c57daae98 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Fri, 27 Jul 2012 11:50:25 +0000 Subject: [PATCH] mod_proxy_balancer: Restore balancing after a failed worker has recovered when using lbmethod_bybusyness. PR: 48735 Markus Stoll and Adam C both submitted patches against 2.2.x to bug 48735. Compared with those two, this solution 1. resets the busy field in the error-ed worker at the end of the request instead of at recovery time 2. leaves the lbstatus field alone 3. covers all possible scenarios where the busy field in the error-ed worker needs to be adjusted, since a cleanup to perform the decrement is registered at the point of the increment git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1366344 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ modules/proxy/mod_proxy_balancer.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 87345203bd..ff79d4c51d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) mod_proxy_balancer: Restore balancing after a failed worker has + recovered when using lbmethod_bybusyness. PR 48735. [Jeff Trawick] + *) mod_proxy: Fix memory leak or possible corruption in ProxyBlock implementation. [Ruediger Pluem, Joe Orton] diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c index e3db4883f1..26bb1a8856 100644 --- a/modules/proxy/mod_proxy_balancer.c +++ b/modules/proxy/mod_proxy_balancer.c @@ -437,6 +437,17 @@ static void force_recovery(proxy_balancer *balancer, server_rec *s) } } +static apr_status_t decrement_busy_count(void *worker_) +{ + proxy_worker *worker = worker_; + + if (worker->s->busy) { + worker->s->busy--; + } + + return APR_SUCCESS; +} + static int proxy_balancer_pre_request(proxy_worker **worker, proxy_balancer **balancer, request_rec *r, @@ -570,6 +581,8 @@ static int proxy_balancer_pre_request(proxy_worker **worker, } (*worker)->s->busy++; + apr_pool_cleanup_register(r->pool, *worker, decrement_busy_count, + apr_pool_cleanup_null); /* Add balancer/worker info to env. */ apr_table_setn(r->subprocess_env, @@ -642,11 +655,7 @@ static int proxy_balancer_post_request(proxy_worker *worker, ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01176) "proxy_balancer_post_request for (%s)", balancer->s->name); - if (worker && worker->s->busy) - worker->s->busy--; - return OK; - } static void recalc_factors(proxy_balancer *balancer)