]> git.kaiwu.me - nginx.git/commitdiff
Events: protection from stale events in eventport and devpoll.
authorValentin Bartenev <vbart@nginx.com>
Fri, 12 Apr 2013 15:02:33 +0000 (15:02 +0000)
committerValentin Bartenev <vbart@nginx.com>
Fri, 12 Apr 2013 15:02:33 +0000 (15:02 +0000)
Stale write event may happen if read and write events was reported both,
and processing of the read event closed descriptor.

In practice this might result in "sendfilev() failed (134: ..." or
"writev() failed (134: ..." errors when switching to next upstream server.

See report here:
http://mailman.nginx.org/pipermail/nginx/2013-April/038421.html

src/event/modules/ngx_devpoll_module.c
src/event/modules/ngx_eventport_module.c

index d09b5bc07adc9773445e7d28d9685a46923fa43a..5f78cd7d32204c6e0b9d2d16deba2091742534ae 100644 (file)
@@ -343,7 +343,7 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
     ngx_fd_t            fd;
     ngx_err_t           err;
     ngx_int_t           i;
-    ngx_uint_t          level;
+    ngx_uint_t          level, instance;
     ngx_event_t        *rev, *wev, **queue;
     ngx_connection_t   *c;
     struct pollfd       pfd;
@@ -510,7 +510,13 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
                 ngx_locked_post_event(rev, queue);
 
             } else {
+                instance = rev->instance;
+
                 rev->handler(rev);
+
+                if (c->fd == -1 || wev->instance != instance) {
+                    continue;
+                }
             }
         }
 
index d6dcb0bedf4cbb8cb4ae87f52fd1af35b597f89c..5f9cf4e35fbabacfa020436b52d867b2544523f6 100644 (file)
@@ -551,7 +551,7 @@ ngx_eventport_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
                 } else {
                     rev->handler(rev);
 
-                    if (ev->closed) {
+                    if (ev->closed || ev->instance != instance) {
                         continue;
                     }
                 }