diff -ru nginx-1.2.7/src/event/modules/ngx_epoll_module.c nginx-1.2.7-eof/src/event/modules/ngx_epoll_module.c --- nginx-1.2.7/src/event/modules/ngx_epoll_module.c 2012-08-06 13:07:28.000000000 -0400 +++ nginx-1.2.7-eof/src/event/modules/ngx_epoll_module.c 2013-03-19 00:17:05.000000000 -0400 @@ -24,6 +24,7 @@ #define EPOLLMSG 0x400 #define EPOLLERR 0x008 #define EPOLLHUP 0x010 +#define EPOLLRDHUP 0x2000 #define EPOLLET 0x80000000 #define EPOLLONESHOT 0x40000000 @@ -399,10 +400,11 @@ #if (NGX_READ_EVENT != EPOLLIN) events = EPOLLIN; #endif + events |= EPOLLRDHUP; } else { e = c->read; - prev = EPOLLIN; + prev = EPOLLIN | EPOLLRDHUP; #if (NGX_WRITE_EVENT != EPOLLOUT) events = EPOLLOUT; #endif @@ -466,7 +468,7 @@ } else { e = c->read; - prev = EPOLLIN; + prev = EPOLLIN | EPOLLRDHUP; } if (e->active) { @@ -671,6 +674,9 @@ } else { rev->ready = 1; + if (revents & EPOLLRDHUP) { + rev->pending_eof = 1; + } } if (flags & NGX_POST_EVENTS) { diff -ru nginx-1.2.7/src/http/ngx_http_upstream.c nginx-1.2.7-eof/src/http/ngx_http_upstream.c --- nginx-1.2.7/src/http/ngx_http_upstream.c 2013-02-11 09:39:49.000000000 -0500 +++ nginx-1.2.7-eof/src/http/ngx_http_upstream.c 2013-03-18 22:50:35.000000000 -0400 @@ -999,9 +999,11 @@ return; } -#if (NGX_HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) || (NGX_HAVE_EPOLL) + + if (ngx_event_flags & (NGX_USE_KQUEUE_EVENT | NGX_USE_EPOLL_EVENT)) { - if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { + int ev_errno = 0; if (!ev->pending_eof) { return; @@ -1010,21 +1012,24 @@ ev->eof = 1; c->error = 1; +#if (NGX_HAVE_KQUEUE) if (ev->kq_errno) { ev->error = 1; + ev_errno = ev->kq_errno; } +#endif if (!u->cacheable && u->peer.connection) { - ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, - "kevent() reported that client prematurely closed " + ngx_log_error(NGX_LOG_INFO, ev->log, ev_errno, + "kevent()/epoll_wait() reported that client prematurely closed " "connection, so upstream connection is closed too"); ngx_http_upstream_finalize_request(r, u, NGX_HTTP_CLIENT_CLOSED_REQUEST); return; } - ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, - "kevent() reported that client prematurely closed " + ngx_log_error(NGX_LOG_INFO, ev->log, ev_errno, + "kevent()/epoll_wait() reported that client prematurely closed " "connection"); if (u->peer.connection == NULL) {