diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2018-04-03 02:43:18 +0300 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2018-04-03 02:43:18 +0300 |
commit | d90a75b7cdc70ddb2aa1880dc09301c5f1a279ae (patch) | |
tree | 4a617005b3092c7a457fb32ac0e4a76366257c50 /src/http/ngx_http_upstream.c | |
parent | cadc8ca306e42a97c6a7b89468745d154314aa84 (diff) | |
download | nginx-d90a75b7cdc70ddb2aa1880dc09301c5f1a279ae.tar.gz nginx-d90a75b7cdc70ddb2aa1880dc09301c5f1a279ae.zip |
Upstream: fixed ngx_http_upstream_test_next() conditions.
Previously, ngx_http_upstream_test_next() used an outdated condition on
whether it will be possible to switch to a different server or not. It
did not take into account restrictions on non-idempotent requests, requests
with non-buffered request body, and the next upstream timeout.
For such requests, switching to the next upstream server was rejected
later in ngx_http_upstream_next(), resulting in nginx own error page
being returned instead of the original upstream response.
Diffstat (limited to 'src/http/ngx_http_upstream.c')
-rw-r--r-- | src/http/ngx_http_upstream.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index e6f9c09dc..a415f58e3 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -2389,7 +2389,8 @@ ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u) static ngx_int_t ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u) { - ngx_uint_t status; + ngx_msec_t timeout; + ngx_uint_t status, mask; ngx_http_upstream_next_t *un; status = u->headers_in.status_n; @@ -2400,7 +2401,22 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u) continue; } - if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) { + timeout = u->conf->next_upstream_timeout; + + if (u->request_sent + && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH))) + { + mask = un->mask | NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT; + + } else { + mask = un->mask; + } + + if (u->peer.tries > 1 + && ((u->conf->next_upstream & mask) == mask) + && !(u->request_sent && r->request_body_no_buffering) + && !(timeout && ngx_current_msec - u->peer.start_time >= timeout)) + { ngx_http_upstream_next(r, u, un->mask); return NGX_OK; } |