diff src/http/ngx_http_upstream_round_robin.c @ 330:5e3b425174f6 NGINX_0_6_9

nginx 0.6.9 *) Bugfix: a worker process may got caught in an endless loop, if the HTTPS protocol was used; bug appeared in 0.6.7. *) Bugfix: if server listened on two addresses or ports and trailing wildcard was used, then nginx did not run. *) Bugfix: the "ip_hash" directive might incorrectly mark servers as down. *) Bugfix: nginx could not be built on amd64; bug appeared in 0.6.8.
author Igor Sysoev <http://sysoev.ru>
date Tue, 28 Aug 2007 00:00:00 +0400
parents 9fc4ab6673f9
children 3a91bfeffaba
line wrap: on
line diff
--- a/src/http/ngx_http_upstream_round_robin.c
+++ b/src/http/ngx_http_upstream_round_robin.c
@@ -303,6 +303,8 @@ ngx_http_upstream_get_round_robin_peer(n
 
             /* it's a first try - get a current peer */
 
+            i = pc->tries;
+
             for ( ;; ) {
                 rrp->current = ngx_http_upstream_get_peer(rrp->peers);
 
@@ -339,16 +341,24 @@ ngx_http_upstream_get_round_robin_peer(n
                     pc->tries--;
                 }
 
-                if (pc->tries) {
-                    continue;
+                if (pc->tries == 0) {
+                    goto failed;
                 }
 
-                goto failed;
+                if (--i == 0) {
+                    ngx_log_error(NGX_LOG_ALERT, pc->log, 0,
+                                  "round robin upstream stuck on %ui tries",
+                                  pc->tries);
+                    goto failed;
+                }
             }
 
             peer->current_weight--;
 
         } else {
+
+            i = pc->tries;
+
             for ( ;; ) {
                 n = rrp->current / (8 * sizeof(uintptr_t));
                 m = (uintptr_t) 1 << rrp->current % (8 * sizeof(uintptr_t));
@@ -385,11 +395,16 @@ ngx_http_upstream_get_round_robin_peer(n
                     rrp->current = 0;
                 }
 
-                if (pc->tries) {
-                    continue;
+                if (pc->tries == 0) {
+                    goto failed;
                 }
 
-                goto failed;
+                if (--i == 0) {
+                    ngx_log_error(NGX_LOG_ALERT, pc->log, 0,
+                                  "round robin upstream stuck on %ui tries",
+                                  pc->tries);
+                    goto failed;
+                }
             }
 
             peer->current_weight--;
@@ -500,7 +515,7 @@ ngx_http_upstream_get_peer(ngx_http_upst
 
         for (i = 0; i < peers->number; i++) {
             if (peer[i].fails == 0) {
-                peer[i].current_weight += peer[i].weight;
+                peer[i].current_weight = peer[i].weight;
 
             } else {
                 /* 1 allows to go to quick recovery when all peers failed */