]> git.kaiwu.me - nginx.git/commitdiff
Stream: prevent repeated event notifications after eof.
authorRoman Arutyunyan <arut@nginx.com>
Wed, 22 Apr 2015 16:55:04 +0000 (19:55 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Wed, 22 Apr 2015 16:55:04 +0000 (19:55 +0300)
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.

src/stream/ngx_stream_proxy_module.c

index 98a9aba06c76ee275d5973df49915a1c16e62f27..8727629fddb260959a34dfbc983060a5b4a8e969 100644 (file)
@@ -814,6 +814,7 @@ ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
     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_session_t *s, ngx_uint_t from_upstream,
         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;
     }