]> git.kaiwu.me - nginx.git/commitdiff
Protection from stale write events in epoll.
authorMaxim Dounin <mdounin@mdounin.ru>
Tue, 22 Nov 2011 17:02:21 +0000 (17:02 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Tue, 22 Nov 2011 17:02:21 +0000 (17:02 +0000)
Stale write event may happen if epoll_wait() reported both read and write
events, and processing of the read event closed descriptor.

Patch by Yichun Zhang (agentzh).

src/event/modules/ngx_epoll_module.c

index 31c10c6dc86f76c0047ccb4271f890063e41f269..4f9c5118e7f492fdba10e213b3dd336cb9813287 100644 (file)
@@ -681,6 +681,18 @@ ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
 
         wev = c->write;
 
+        if (c->fd == -1 || wev->instance != instance) {
+
+            /*
+             * the stale event from a file descriptor
+             * that was just closed in this iteration
+             */
+
+            ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+                           "epoll: stale event %p", c);
+            continue;
+        }
+
         if ((revents & EPOLLOUT) && wev->active) {
 
             if (flags & NGX_POST_THREAD_EVENTS) {