comparison src/http/ngx_http_upstream.c @ 7126:77fe752b4586

Upstream: fixed error handling of stale and revalidated cache send. The NGX_DONE value returned from ngx_http_upstream_cache_send() indicates that upstream was already finalized in ngx_http_upstream_process_headers(). It was treated as a generic error which resulted in duplicate finalization. Handled NGX_HTTP_UPSTREAM_INVALID_HEADER from ngx_http_upstream_cache_send(). Previously, it could return within ngx_http_upstream_finalize_request(), and since it's below NGX_HTTP_SPECIAL_RESPONSE, a client connection could stuck.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 10 Oct 2017 01:04:54 +0300
parents b8fc701daf8e
children 882ad033d43c
comparison
equal deleted inserted replaced
7125:b8fc701daf8e 7126:77fe752b4586
2402 { 2402 {
2403 ngx_int_t rc; 2403 ngx_int_t rc;
2404 2404
2405 rc = u->reinit_request(r); 2405 rc = u->reinit_request(r);
2406 2406
2407 if (rc == NGX_OK) { 2407 if (rc != NGX_OK) {
2408 u->cache_status = NGX_HTTP_CACHE_STALE; 2408 ngx_http_upstream_finalize_request(r, u, rc);
2409 rc = ngx_http_upstream_cache_send(r, u); 2409 return NGX_OK;
2410 }
2411
2412 u->cache_status = NGX_HTTP_CACHE_STALE;
2413 rc = ngx_http_upstream_cache_send(r, u);
2414
2415 if (rc == NGX_DONE) {
2416 return NGX_OK;
2417 }
2418
2419 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
2420 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
2410 } 2421 }
2411 2422
2412 ngx_http_upstream_finalize_request(r, u, rc); 2423 ngx_http_upstream_finalize_request(r, u, rc);
2413 return NGX_OK; 2424 return NGX_OK;
2414 } 2425 }
2441 return NGX_OK; 2452 return NGX_OK;
2442 } 2453 }
2443 2454
2444 u->cache_status = NGX_HTTP_CACHE_REVALIDATED; 2455 u->cache_status = NGX_HTTP_CACHE_REVALIDATED;
2445 rc = ngx_http_upstream_cache_send(r, u); 2456 rc = ngx_http_upstream_cache_send(r, u);
2457
2458 if (rc == NGX_DONE) {
2459 return NGX_OK;
2460 }
2461
2462 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
2463 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
2464 }
2446 2465
2447 if (valid == 0) { 2466 if (valid == 0) {
2448 valid = r->cache->valid_sec; 2467 valid = r->cache->valid_sec;
2449 updating = r->cache->updating_sec; 2468 updating = r->cache->updating_sec;
2450 error = r->cache->error_sec; 2469 error = r->cache->error_sec;
4148 { 4167 {
4149 ngx_int_t rc; 4168 ngx_int_t rc;
4150 4169
4151 rc = u->reinit_request(r); 4170 rc = u->reinit_request(r);
4152 4171
4153 if (rc == NGX_OK) { 4172 if (rc != NGX_OK) {
4154 u->cache_status = NGX_HTTP_CACHE_STALE; 4173 ngx_http_upstream_finalize_request(r, u, rc);
4155 rc = ngx_http_upstream_cache_send(r, u); 4174 return;
4175 }
4176
4177 u->cache_status = NGX_HTTP_CACHE_STALE;
4178 rc = ngx_http_upstream_cache_send(r, u);
4179
4180 if (rc == NGX_DONE) {
4181 return;
4182 }
4183
4184 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
4185 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
4156 } 4186 }
4157 4187
4158 ngx_http_upstream_finalize_request(r, u, rc); 4188 ngx_http_upstream_finalize_request(r, u, rc);
4159 return; 4189 return;
4160 } 4190 }