[nginx] Stream: prevent repeated event notifications after eof.

Roman Arutyunyan arut at nginx.com
Wed Apr 22 16:56:32 UTC 2015


details:   http://hg.nginx.org/nginx/rev/f1f222db290b
branches:  
changeset: 6124:f1f222db290b
user:      Roman Arutyunyan <arut at nginx.com>
date:      Wed Apr 22 19:55:04 2015 +0300
description:
Stream: prevent repeated event notifications after eof.

When client or upstream connection is closed, level-triggered read event
remained active until the end of the session leading to cpu hog.  Now the flag
NGX_CLOSE_EVENT is used to unschedule the event.

diffstat:

 src/stream/ngx_stream_proxy_module.c |  5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diffs (22 lines):

diff -r caa103acf180 -r f1f222db290b src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c	Wed Apr 22 18:37:34 2015 +0300
+++ b/src/stream/ngx_stream_proxy_module.c	Wed Apr 22 19:55:04 2015 +0300
@@ -814,6 +814,7 @@ ngx_stream_proxy_process(ngx_stream_sess
     size_t                        size;
     ssize_t                       n;
     ngx_buf_t                    *b;
+    ngx_uint_t                    flags;
     ngx_connection_t             *c, *pc, *src, *dst;
     ngx_log_handler_pt            handler;
     ngx_stream_upstream_t        *u;
@@ -911,7 +912,9 @@ ngx_stream_proxy_process(ngx_stream_sess
         return NGX_DONE;
     }
 
-    if (ngx_handle_read_event(src->read, 0) != NGX_OK) {
+    flags = src->read->eof ? NGX_CLOSE_EVENT : 0;
+
+    if (ngx_handle_read_event(src->read, flags) != NGX_OK) {
         ngx_stream_proxy_finalize(s, NGX_ERROR);
         return NGX_ERROR;
     }



More information about the nginx-devel mailing list