summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Arutyunyan <arut@nginx.com>2017-05-29 23:33:38 +0300
committerRoman Arutyunyan <arut@nginx.com>2017-05-29 23:33:38 +0300
commitd1d48ed8448e24ef5297bb37387544ad241591fe (patch)
tree6ac03bb381adf0c2d444842eb157b4028ba56c62
parent529ce100586015c75363846c372f484a3ca555fa (diff)
downloadnginx-d1d48ed8448e24ef5297bb37387544ad241591fe.tar.gz
Fixed background requests with asynchronous operations.
If the main request was finalized while a background request performed an asynchronous operation, the main request ended up in ngx_http_writer() and was not finalized until a network event or a timeout. For example, cache background update with aio enabled made nginx unable to process further client requests or close the connection, keeping it open until client closes it. Now regular finalization of the main request is not suspended because of an asynchronous operation in another request. If a background request was terminated while an asynchronous operation was in progress, background request's write event handler was changed to ngx_http_request_finalizer() and never called again. Now, whenever a request is terminated while an asynchronous operation is in progress, connection error flag is set to make further finalizations of any request with this connection lead to termination. These issues appeared in 1aeaae6e9446 (not yet released).
-rw-r--r--src/http/ngx_http_request.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index fd6b513dc..cc3722fb3 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -2331,10 +2331,6 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
return;
}
- if (r->main->blocked) {
- r->write_event_handler = ngx_http_request_finalizer;
- }
-
ngx_http_terminate_request(r, rc);
return;
}
@@ -2449,7 +2445,7 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
return;
}
- if (r->buffered || c->buffered || r->postponed || r->blocked) {
+ if (r->buffered || c->buffered || r->postponed) {
if (ngx_http_set_write_handler(r) != NGX_OK) {
ngx_http_terminate_request(r, 0);
@@ -2530,6 +2526,8 @@ ngx_http_terminate_request(ngx_http_request_t *r, ngx_int_t rc)
if (mr->write_event_handler) {
if (mr->blocked) {
+ r->connection->error = 1;
+ r->write_event_handler = ngx_http_request_finalizer;
return;
}