Mercurial > hg > nginx-quic
comparison src/http/ngx_http_upstream.c @ 7255:4db4fe3bdeda
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 03 Apr 2018 02:43:18 +0300 |
parents | 400a3412b1e3 |
children | 08f114ed5449 |
comparison
equal
deleted
inserted
replaced
7254:1fd992589ffe | 7255:4db4fe3bdeda |
---|---|
2387 | 2387 |
2388 | 2388 |
2389 static ngx_int_t | 2389 static ngx_int_t |
2390 ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u) | 2390 ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u) |
2391 { | 2391 { |
2392 ngx_uint_t status; | 2392 ngx_msec_t timeout; |
2393 ngx_uint_t status, mask; | |
2393 ngx_http_upstream_next_t *un; | 2394 ngx_http_upstream_next_t *un; |
2394 | 2395 |
2395 status = u->headers_in.status_n; | 2396 status = u->headers_in.status_n; |
2396 | 2397 |
2397 for (un = ngx_http_upstream_next_errors; un->status; un++) { | 2398 for (un = ngx_http_upstream_next_errors; un->status; un++) { |
2398 | 2399 |
2399 if (status != un->status) { | 2400 if (status != un->status) { |
2400 continue; | 2401 continue; |
2401 } | 2402 } |
2402 | 2403 |
2403 if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) { | 2404 timeout = u->conf->next_upstream_timeout; |
2405 | |
2406 if (u->request_sent | |
2407 && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH))) | |
2408 { | |
2409 mask = un->mask | NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT; | |
2410 | |
2411 } else { | |
2412 mask = un->mask; | |
2413 } | |
2414 | |
2415 if (u->peer.tries > 1 | |
2416 && ((u->conf->next_upstream & mask) == mask) | |
2417 && !(u->request_sent && r->request_body_no_buffering) | |
2418 && !(timeout && ngx_current_msec - u->peer.start_time >= timeout)) | |
2419 { | |
2404 ngx_http_upstream_next(r, u, un->mask); | 2420 ngx_http_upstream_next(r, u, un->mask); |
2405 return NGX_OK; | 2421 return NGX_OK; |
2406 } | 2422 } |
2407 | 2423 |
2408 #if (NGX_HTTP_CACHE) | 2424 #if (NGX_HTTP_CACHE) |