Welcome! Log In Create A New Profile

Advanced

[nginx] Fixed premature background subrequest finalization.

Dmitry Volyntsev
March 02, 2020 12:32PM
details: https://hg.nginx.org/nginx/rev/b4dbf8b98f9a
branches:
changeset: 7631:b4dbf8b98f9a
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Mar 02 20:07:36 2020 +0300
description:
Fixed premature background subrequest finalization.

When "aio" or "aio threads" is used while processing the response body of an
in-memory background subrequest, the subrequest could be finalized with an aio
operation still in progress. Upon aio completion either parent request is
woken or the old r->write_event_handler is called again. The latter may result
in request errors. In either case post_subrequest handler is never called with
the full response body, which is typically expected when using in-memory
subrequests.

Currently in nginx background subrequests are created by the upstream module
and the mirror module. The issue does not manifest itself with these
subrequests because they are header-only. But it can manifest itself with
third-party modules which create in-memory background subrequests.

diffstat:

src/http/ngx_http_request.c | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)

diffs (35 lines):

diff -r f001d9384293 -r b4dbf8b98f9a src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c Fri Feb 28 17:21:18 2020 +0300
+++ b/src/http/ngx_http_request.c Mon Mar 02 20:07:36 2020 +0300
@@ -2490,6 +2490,15 @@ ngx_http_finalize_request(ngx_http_reque
if (r != r->main) {
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

+ if (r->buffered || r->postponed) {
+
+ if (ngx_http_set_write_handler(r) != NGX_OK) {
+ ngx_http_terminate_request(r, 0);
+ }
+
+ return;
+ }
+
if (r->background) {
if (!r->logged) {
if (clcf->log_subrequest) {
@@ -2509,15 +2518,6 @@ ngx_http_finalize_request(ngx_http_reque
return;
}

- if (r->buffered || r->postponed) {
-
- if (ngx_http_set_write_handler(r) != NGX_OK) {
- ngx_http_terminate_request(r, 0);
- }
-
- return;
- }
-
pr = r->parent;

if (r == c->data) {
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Fixed premature background subrequest finalization.

Dmitry Volyntsev 327 March 02, 2020 12:32PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 302
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready