mirror of
https://github.com/nginx/nginx.git
synced 2025-06-21 21:31:05 +08:00
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
This commit is contained in:
parent
e95ea5b878
commit
8d6de94f5b
@ -1765,20 +1765,77 @@ ngx_http_writer(ngx_http_request_t *r)
|
|||||||
static void
|
static void
|
||||||
ngx_http_block_read(ngx_http_request_t *r)
|
ngx_http_block_read(ngx_http_request_t *r)
|
||||||
{
|
{
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
int n;
|
||||||
"http read blocked");
|
char buf[1];
|
||||||
|
ngx_err_t err;
|
||||||
|
ngx_event_t *rev;
|
||||||
|
ngx_connection_t *c;
|
||||||
|
|
||||||
|
c = r->connection;
|
||||||
|
rev = c->read;
|
||||||
|
|
||||||
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http read blocked");
|
||||||
|
|
||||||
|
#if (NGX_HAVE_KQUEUE)
|
||||||
|
|
||||||
|
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
|
||||||
|
|
||||||
|
if (!rev->pending_eof) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rev->eof = 1;
|
||||||
|
c->error = 1;
|
||||||
|
err = rev->kq_errno;
|
||||||
|
|
||||||
|
goto closed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
n = recv(c->fd, buf, 1, MSG_PEEK);
|
||||||
|
|
||||||
|
if (n == 0) {
|
||||||
|
rev->eof = 1;
|
||||||
|
c->error = 1;
|
||||||
|
err = 0;
|
||||||
|
|
||||||
|
goto closed;
|
||||||
|
|
||||||
|
} else if (n == -1) {
|
||||||
|
err = ngx_socket_errno;
|
||||||
|
|
||||||
|
if (err != NGX_EAGAIN) {
|
||||||
|
rev->eof = 1;
|
||||||
|
c->error = 1;
|
||||||
|
|
||||||
|
goto closed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* aio does not call this handler */
|
/* aio does not call this handler */
|
||||||
|
|
||||||
if ((ngx_event_flags & NGX_USE_LEVEL_EVENT)
|
if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && rev->active) {
|
||||||
&& r->connection->read->active)
|
|
||||||
{
|
if (ngx_del_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) {
|
||||||
if (ngx_del_event(r->connection->read, NGX_READ_EVENT, 0)
|
|
||||||
== NGX_ERROR)
|
|
||||||
{
|
|
||||||
ngx_http_close_request(r, 0);
|
ngx_http_close_request(r, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
closed:
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
rev->error = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_log_error(NGX_LOG_INFO, c->log, err,
|
||||||
|
"client closed prematurely connection");
|
||||||
|
|
||||||
|
ngx_http_close_request(r, 0);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user