comparison src/http/ngx_http_upstream_round_robin.c @ 1419:79f033a89dd4

add guard code to prevent endless loop
author Igor Sysoev <igor@sysoev.ru>
date Fri, 24 Aug 2007 15:58:13 +0000
parents ab553c23bd3a
children debd1ba60d3f
comparison
equal deleted inserted replaced
1418:acb1f441e7b2 1419:79f033a89dd4
301 301
302 if (pc->tries == rrp->peers->number) { 302 if (pc->tries == rrp->peers->number) {
303 303
304 /* it's a first try - get a current peer */ 304 /* it's a first try - get a current peer */
305 305
306 i = pc->tries;
307
306 for ( ;; ) { 308 for ( ;; ) {
307 rrp->current = ngx_http_upstream_get_peer(rrp->peers); 309 rrp->current = ngx_http_upstream_get_peer(rrp->peers);
308 310
309 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0, 311 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
310 "get rr peer, current: %ui %i", 312 "get rr peer, current: %ui %i",
337 } 339 }
338 340
339 pc->tries--; 341 pc->tries--;
340 } 342 }
341 343
342 if (pc->tries) { 344 if (pc->tries == 0) {
343 continue; 345 goto failed;
344 } 346 }
345 347
346 goto failed; 348 if (--i == 0) {
349 ngx_log_error(NGX_LOG_ALERT, pc->log, 0,
350 "round robin upstream stuck on %ui tries",
351 pc->tries);
352 goto failed;
353 }
347 } 354 }
348 355
349 peer->current_weight--; 356 peer->current_weight--;
350 357
351 } else { 358 } else {
359
360 i = pc->tries;
361
352 for ( ;; ) { 362 for ( ;; ) {
353 n = rrp->current / (8 * sizeof(uintptr_t)); 363 n = rrp->current / (8 * sizeof(uintptr_t));
354 m = (uintptr_t) 1 << rrp->current % (8 * sizeof(uintptr_t)); 364 m = (uintptr_t) 1 << rrp->current % (8 * sizeof(uintptr_t));
355 365
356 if (!(rrp->tried[n] & m)) { 366 if (!(rrp->tried[n] & m)) {
383 393
384 if (rrp->current >= rrp->peers->number) { 394 if (rrp->current >= rrp->peers->number) {
385 rrp->current = 0; 395 rrp->current = 0;
386 } 396 }
387 397
388 if (pc->tries) { 398 if (pc->tries == 0) {
389 continue; 399 goto failed;
390 } 400 }
391 401
392 goto failed; 402 if (--i == 0) {
403 ngx_log_error(NGX_LOG_ALERT, pc->log, 0,
404 "round robin upstream stuck on %ui tries",
405 pc->tries);
406 goto failed;
407 }
393 } 408 }
394 409
395 peer->current_weight--; 410 peer->current_weight--;
396 } 411 }
397 412