Skip to content

Commit 0dc73de

Browse files
committed
Merge r572937, r574485, r574486 from trunk:
Be proactively safe. A cheap check, but helps prevents badness :) * Do not reset lbstatus, lbfactor and lbset if the shared proxy_worker_stat structure for a worker is already initialized by the same or another process. * This check is now part of the PROXY_WORKER_IS_INITIALIZED macro. Reviewed by: jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@575708 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4c77bb6 commit 0dc73de

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

modules/proxy/mod_proxy.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,16 @@ struct proxy_conn_pool {
254254
#define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
255255
PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
256256

257-
#define PROXY_WORKER_IS_INITIALIZED(f) ( (f)->s->status & \
258-
PROXY_WORKER_INITIALIZED )
257+
/* NOTE: these check the shared status */
258+
#define PROXY_WORKER_IS_INITIALIZED(f) ( (f)->s && \
259+
( (f)->s->status & PROXY_WORKER_INITIALIZED ) )
259260

260-
#define PROXY_WORKER_IS_STANDBY(f) ( (f)->s->status & \
261-
PROXY_WORKER_HOT_STANDBY )
261+
#define PROXY_WORKER_IS_STANDBY(f) ( (f)->s && \
262+
( (f)->s->status & PROXY_WORKER_HOT_STANDBY ) )
262263

263-
#define PROXY_WORKER_IS_USABLE(f) ( !((f)->s->status & \
264-
(PROXY_WORKER_NOT_USABLE_BITMAP)) && PROXY_WORKER_IS_INITIALIZED(f) )
264+
#define PROXY_WORKER_IS_USABLE(f) ( (f)->s && \
265+
( !( (f)->s->status & PROXY_WORKER_NOT_USABLE_BITMAP) ) && \
266+
PROXY_WORKER_IS_INITIALIZED(f) )
265267

266268
/* default worker retry timeout in seconds */
267269
#define PROXY_WORKER_DEFAULT_RETRY 60

modules/proxy/mod_proxy_balancer.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define CORE_PRIVATE
2020

2121
#include "mod_proxy.h"
22+
#include "scoreboard.h"
2223
#include "ap_mpm.h"
2324
#include "apr_version.h"
2425
#include "apr_hooks.h"
@@ -79,22 +80,37 @@ static int init_balancer_members(proxy_server_conf *conf, server_rec *s,
7980
{
8081
int i;
8182
proxy_worker *workers;
83+
int worker_is_initialized;
84+
proxy_worker_stat *slot;
8285

8386
workers = (proxy_worker *)balancer->workers->elts;
8487

8588
for (i = 0; i < balancer->workers->nelts; i++) {
89+
worker_is_initialized = PROXY_WORKER_IS_INITIALIZED(workers);
90+
if (!worker_is_initialized) {
91+
/*
92+
* If the worker is not initialized check whether its scoreboard
93+
* slot is already initialized.
94+
*/
95+
slot = (proxy_worker_stat *) ap_get_scoreboard_lb(workers->id);
96+
if (slot) {
97+
worker_is_initialized = slot->status & PROXY_WORKER_INITIALIZED;
98+
}
99+
else {
100+
worker_is_initialized = 0;
101+
}
102+
}
86103
ap_proxy_initialize_worker_share(conf, workers, s);
87104
ap_proxy_initialize_worker(workers, s);
105+
if (!worker_is_initialized) {
106+
/* Set to the original configuration */
107+
workers->s->lbstatus = workers->s->lbfactor =
108+
(workers->lbfactor ? workers->lbfactor : 1);
109+
workers->s->lbset = workers->lbset;
110+
}
88111
++workers;
89112
}
90113

91-
workers = (proxy_worker *)balancer->workers->elts;
92-
for (i = 0; i < balancer->workers->nelts; i++) {
93-
/* Set to the original configuration */
94-
workers[i].s->lbstatus = workers[i].s->lbfactor =
95-
(workers[i].lbfactor ? workers[i].lbfactor : 1);
96-
workers[i].s->lbset = workers[i].lbset;
97-
}
98114
/* Set default number of attempts to the number of
99115
* workers.
100116
*/

modules/proxy/proxy_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ PROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf,
16501650
void *score = NULL;
16511651
#endif
16521652

1653-
if (worker->s && PROXY_WORKER_IS_INITIALIZED(worker)) {
1653+
if (PROXY_WORKER_IS_INITIALIZED(worker)) {
16541654
/* The worker share is already initialized */
16551655
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
16561656
"proxy: worker %s already initialized",

0 commit comments

Comments
 (0)