diff src/event/ngx_event_udp.c @ 7440:6d4bc025c5a7

Prevented scheduling events on a shared connection. A shared connection does not own its file descriptor, which means that ngx_handle_read_event/ngx_handle_write_event calls should do nothing for it. Currently the c->shared flag is checked in several places in the stream proxy module prior to calling these functions. However it was not done everywhere. Missing checks could lead to calling ngx_handle_read_event/ngx_handle_write_event on shared connections. The problem manifested itself when using proxy_upload_rate and resulted in either duplicate file descriptor error (e.g. with epoll) or incorrect further udp packet processing (e.g. with kqueue). The fix is to set and reset the event active flag in a way that prevents ngx_handle_read_event/ngx_handle_write_event from scheduling socket events.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 14 Jan 2019 20:36:23 +0300
parents 4698cede59ff
children fdc3d40979b0 45db1b5c1706
line wrap: on
line diff
--- a/src/event/ngx_event_udp.c
+++ b/src/event/ngx_event_udp.c
@@ -256,7 +256,9 @@ ngx_event_recvmsg(ngx_event_t *ev)
             rev = c->read;
 
             c->udp->buffer = &buf;
+
             rev->ready = 1;
+            rev->active = 0;
 
             rev->handler(rev);
 
@@ -265,6 +267,7 @@ ngx_event_recvmsg(ngx_event_t *ev)
             }
 
             rev->ready = 0;
+            rev->active = 1;
 
             goto next;
         }
@@ -343,6 +346,7 @@ ngx_event_recvmsg(ngx_event_t *ev)
         rev = c->read;
         wev = c->write;
 
+        rev->active = 1;
         wev->ready = 1;
 
         rev->log = log;
@@ -453,7 +457,9 @@ ngx_udp_shared_recv(ngx_connection_t *c,
     ngx_memcpy(buf, b->pos, n);
 
     c->udp->buffer = NULL;
+
     c->read->ready = 0;
+    c->read->active = 1;
 
     return n;
 }