Welcome! Log In Create A New Profile

Advanced

[nginx] Upstream: fixed EOF handling in unbuffered and upgraded modes.

Maxim Dounin
July 18, 2019 11:30AM
details: https://hg.nginx.org/nginx/rev/08ed570ad93c
branches:
changeset: 7538:08ed570ad93c
user: Maxim Dounin <mdounin@mdounin.ru>
date: Thu Jul 18 18:27:52 2019 +0300
description:
Upstream: fixed EOF handling in unbuffered and upgraded modes.

With level-triggered event methods it is important to specify
the NGX_CLOSE_EVENT flag to ngx_handle_read_event(), otherwise
the event won't be removed, resulting in CPU hog.

Reported by Patrick Wollgast.

diffstat:

src/http/ngx_http_upstream.c | 29 ++++++++++++++++++++++++++---
1 files changed, 26 insertions(+), 3 deletions(-)

diffs (67 lines):

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -3334,6 +3334,7 @@ ngx_http_upstream_process_upgraded(ngx_h
size_t size;
ssize_t n;
ngx_buf_t *b;
+ ngx_uint_t flags;
ngx_connection_t *c, *downstream, *upstream, *dst, *src;
ngx_http_upstream_t *u;
ngx_http_core_loc_conf_t *clcf;
@@ -3472,7 +3473,14 @@ ngx_http_upstream_process_upgraded(ngx_h
ngx_del_timer(upstream->write);
}

- if (ngx_handle_read_event(upstream->read, 0) != NGX_OK) {
+ if (upstream->read->eof || upstream->read->error) {
+ flags = NGX_CLOSE_EVENT;
+
+ } else {
+ flags = 0;
+ }
+
+ if (ngx_handle_read_event(upstream->read, flags) != NGX_OK) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
@@ -3491,7 +3499,14 @@ ngx_http_upstream_process_upgraded(ngx_h
return;
}

- if (ngx_handle_read_event(downstream->read, 0) != NGX_OK) {
+ if (downstream->read->eof || downstream->read->error) {
+ flags = NGX_CLOSE_EVENT;
+
+ } else {
+ flags = 0;
+ }
+
+ if (ngx_handle_read_event(downstream->read, flags) != NGX_OK) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
@@ -3563,6 +3578,7 @@ ngx_http_upstream_process_non_buffered_r
ssize_t n;
ngx_buf_t *b;
ngx_int_t rc;
+ ngx_uint_t flags;
ngx_connection_t *downstream, *upstream;
ngx_http_upstream_t *u;
ngx_http_core_loc_conf_t *clcf;
@@ -3666,7 +3682,14 @@ ngx_http_upstream_process_non_buffered_r
ngx_del_timer(downstream->write);
}

- if (ngx_handle_read_event(upstream->read, 0) != NGX_OK) {
+ if (upstream->read->eof || upstream->read->error) {
+ flags = NGX_CLOSE_EVENT;
+
+ } else {
+ flags = 0;
+ }
+
+ if (ngx_handle_read_event(upstream->read, flags) != NGX_OK) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Upstream: fixed EOF handling in unbuffered and upgraded modes.

Maxim Dounin 345 July 18, 2019 11:30AM



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

Online Users

Guests: 298
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