Klaus Demo nginx / 8d6de94
if client closes a connection prematurely, then epoll (at least in Linux 2.6.18) sends EPOLLERR|EPOLLHUP|EPOLLIN only and writer does not know about the error Igor Sysoev 15 years ago
1 changed file(s) with 65 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
17641764 static void
17651765 ngx_http_block_read(ngx_http_request_t *r)
17661766 {
1767 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1768 "http read blocked");
1767 int n;
1768 char buf[1];
1769 ngx_err_t err;
1770 ngx_event_t *rev;
1771 ngx_connection_t *c;
1772
1773 c = r->connection;
1774 rev = c->read;
1775
1776 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http read blocked");
1777
1778 #if (NGX_HAVE_KQUEUE)
1779
1780 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
1781
1782 if (!rev->pending_eof) {
1783 return;
1784 }
1785
1786 rev->eof = 1;
1787 c->error = 1;
1788 err = rev->kq_errno;
1789
1790 goto closed;
1791 }
1792
1793 #endif
1794
1795 n = recv(c->fd, buf, 1, MSG_PEEK);
1796
1797 if (n == 0) {
1798 rev->eof = 1;
1799 c->error = 1;
1800 err = 0;
1801
1802 goto closed;
1803
1804 } else if (n == -1) {
1805 err = ngx_socket_errno;
1806
1807 if (err != NGX_EAGAIN) {
1808 rev->eof = 1;
1809 c->error = 1;
1810
1811 goto closed;
1812 }
1813 }
17691814
17701815 /* aio does not call this handler */
17711816
1772 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT)
1773 && r->connection->read->active)
1774 {
1775 if (ngx_del_event(r->connection->read, NGX_READ_EVENT, 0)
1776 == NGX_ERROR)
1777 {
1817 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && rev->active) {
1818
1819 if (ngx_del_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) {
17781820 ngx_http_close_request(r, 0);
17791821 }
17801822 }
1823
1824 return;
1825
1826 closed:
1827
1828 if (err) {
1829 rev->error = 1;
1830 }
1831
1832 ngx_log_error(NGX_LOG_INFO, c->log, err,
1833 "client closed prematurely connection");
1834
1835 ngx_http_close_request(r, 0);
1836
1837 return;
17811838 }
17821839
17831840