From dd46cc659afe2fc947fc35b22fdd00ae9dd09ff7 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Tue, 25 Dec 2012 08:02:21 +0000 Subject: [PATCH] Upstream: fixed state resetting when switching to backup servers. Based on patch by Thomas Chen (ticket #257). --- src/http/modules/ngx_http_upstream_least_conn_module.c | 4 +++- src/http/ngx_http_upstream_round_robin.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/http/modules/ngx_http_upstream_least_conn_module.c b/src/http/modules/ngx_http_upstream_least_conn_module.c index 21156ae1a..bd2f1bc9e 100644 --- a/src/http/modules/ngx_http_upstream_least_conn_module.c +++ b/src/http/modules/ngx_http_upstream_least_conn_module.c @@ -313,7 +313,9 @@ failed: lcp->rrp.peers = peers->next; pc->tries = lcp->rrp.peers->number; - n = lcp->rrp.peers->number / (8 * sizeof(uintptr_t)) + 1; + n = (lcp->rrp.peers->number + (8 * sizeof(uintptr_t) - 1)) + / (8 * sizeof(uintptr_t)); + for (i = 0; i < n; i++) { lcp->rrp.tried[i] = 0; } diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c index 4b78cffd8..61dce69cb 100644 --- a/src/http/ngx_http_upstream_round_robin.c +++ b/src/http/ngx_http_upstream_round_robin.c @@ -474,7 +474,9 @@ failed: rrp->peers = peers->next; pc->tries = rrp->peers->number; - n = rrp->peers->number / (8 * sizeof(uintptr_t)) + 1; + n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1)) + / (8 * sizeof(uintptr_t)); + for (i = 0; i < n; i++) { rrp->tried[i] = 0; }