Upstream: cached connections now tested against next_upstream.

Much like normal connections, cached connections are now tested against
u->conf->next_upstream, and u->state->status is now always set.

This allows to disable additional tries even with upstream keepalive
by using "proxy_next_upstream off".
This commit is contained in:
Maxim Dounin 2016-03-28 19:49:52 +03:00
parent f5fff1eda0
commit 5a76856dc2

View File

@ -3947,16 +3947,11 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
"upstream timed out"); "upstream timed out");
} }
if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) {
&& (!u->request_sent || !r->request_body_no_buffering))
{
status = 0;
/* TODO: inform balancer instead */ /* TODO: inform balancer instead */
u->peer.tries++; u->peer.tries++;
}
} else {
switch (ft_type) { switch (ft_type) {
case NGX_HTTP_UPSTREAM_FT_TIMEOUT: case NGX_HTTP_UPSTREAM_FT_TIMEOUT:
@ -3983,7 +3978,6 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
default: default:
status = NGX_HTTP_BAD_GATEWAY; status = NGX_HTTP_BAD_GATEWAY;
} }
}
if (r->connection->error) { if (r->connection->error) {
ngx_http_upstream_finalize_request(r, u, ngx_http_upstream_finalize_request(r, u,
@ -3991,8 +3985,8 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
return; return;
} }
if (status) {
u->state->status = status; u->state->status = status;
timeout = u->conf->next_upstream_timeout; timeout = u->conf->next_upstream_timeout;
if (u->peer.tries == 0 if (u->peer.tries == 0
@ -4022,7 +4016,6 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
ngx_http_upstream_finalize_request(r, u, status); ngx_http_upstream_finalize_request(r, u, status);
return; return;
} }
}
if (u->peer.connection) { if (u->peer.connection) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,