Klaus Demo nginx / d90a75b
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 3 years ago
1 changed file(s) with 18 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
23882388 static ngx_int_t
23892389 ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
23902390 {
2391 ngx_uint_t status;
2391 ngx_msec_t timeout;
2392 ngx_uint_t status, mask;
23922393 ngx_http_upstream_next_t *un;
23932394
23942395 status = u->headers_in.status_n;
23992400 continue;
24002401 }
24012402
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 {
24032419 ngx_http_upstream_next(r, u, un->mask);
24042420 return NGX_OK;
24052421 }