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.
Maxim Dounin
4 years ago
2388 | 2388 | static ngx_int_t |
2389 | 2389 | ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u) |
2390 | 2390 | { |
2391 | ngx_uint_t status; | |
2391 | ngx_msec_t timeout; | |
2392 | ngx_uint_t status, mask; | |
2392 | 2393 | ngx_http_upstream_next_t *un; |
2393 | 2394 | |
2394 | 2395 | status = u->headers_in.status_n; |
2399 | 2400 | continue; |
2400 | 2401 | } |
2401 | 2402 | |
2402 | if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) { | |
2403 | timeout = u->conf->next_upstream_timeout; | |
2404 | ||
2405 | if (u->request_sent | |
2406 | && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH))) | |
2407 | { | |
2408 | mask = un->mask | NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT; | |
2409 | ||
2410 | } else { | |
2411 | mask = un->mask; | |
2412 | } | |
2413 | ||
2414 | if (u->peer.tries > 1 | |
2415 | && ((u->conf->next_upstream & mask) == mask) | |
2416 | && !(u->request_sent && r->request_body_no_buffering) | |
2417 | && !(timeout && ngx_current_msec - u->peer.start_time >= timeout)) | |
2418 | { | |
2403 | 2419 | ngx_http_upstream_next(r, u, un->mask); |
2404 | 2420 | return NGX_OK; |
2405 | 2421 | } |