mirror of
https://github.com/nginx/nginx.git
synced 2025-01-24 07:06:35 -06:00
Fixing cpu hog with all upstream servers marked "down".
The following configuration causes nginx to hog cpu due to infinite loop in ngx_http_upstream_get_peer(): upstream backend { server 127.0.0.1:8080 down; server 127.0.0.1:8080 down; } server { ... location / { proxy_pass http://backend; } } Make sure we don't loop infinitely in ngx_http_upstream_get_peer() but stop after resetting peer weights once. Return 0 if we are stuck. This is guaranteed to work as peer 0 always exists, and eventually ngx_http_upstream_get_round_robin_peer() will do the right thing falling back to backup servers or returning NGX_BUSY.
This commit is contained in:
parent
9bc8fc4602
commit
624fbe94a2
@ -585,7 +585,7 @@ failed:
|
|||||||
static ngx_uint_t
|
static ngx_uint_t
|
||||||
ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers)
|
ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers)
|
||||||
{
|
{
|
||||||
ngx_uint_t i, n;
|
ngx_uint_t i, n, reset = 0;
|
||||||
ngx_http_upstream_rr_peer_t *peer;
|
ngx_http_upstream_rr_peer_t *peer;
|
||||||
|
|
||||||
peer = &peers->peer[0];
|
peer = &peers->peer[0];
|
||||||
@ -624,6 +624,10 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reset++) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < peers->number; i++) {
|
for (i = 0; i < peers->number; i++) {
|
||||||
peer[i].current_weight = peer[i].weight;
|
peer[i].current_weight = peer[i].weight;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user