Linux 2.6 epoll Connection timed out

Igor Sysoev is at rambler-co.ru
Thu Jan 18 17:59:43 MSK 2007


On Thu, 18 Jan 2007, voron wrote:

> При обрыве закачки со стороны клиента(отмены закачки в опере, обрыва вгета и 
> тп...) nginx не закрывает сокет до истечения send_timeout, хотя ОСь уже 
> закрыла соединение.
> Всё бы ничего, но в этом случае ограничение сессий работает не так, как надо 
> - зависший сокет считается активным и входит в лимит.

> В дебаг логе смущают записи
>
> 2007/01/18 01:05:20 [debug] 25899#0: epoll: fd:9 ev:0019 d:080C0780
> 2007/01/18 01:05:20 [debug] 25899#0: epoll_wait() error on fd:9 ev:0019
> 2007/01/18 01:05:20 [debug] 25899#0: *1 http read blocked
>
> Т.е судя по ev:0019 = EPOLLERR|EPOLLHUP|EPOLLIN данные пришли в сокет и nginx 
> пытается их прочитать, но чтение блокируется по отсутсвии данных.
>
> Ну и через минуту
> 2007/01/18 01:06:20 [info] 25899#0: *1 client timed out (110: Connection 
> timed out) while sending flv to client

Прилагаемый патч должен помочь.


Игорь Сысоев
http://sysoev.ru
-------------- next part --------------
Index: src/http/ngx_http_request.c
===================================================================
--- src/http/ngx_http_request.c	(revision 362)
+++ src/http/ngx_http_request.c	(working copy)
@@ -1762,20 +1762,77 @@
 static void
 ngx_http_block_read(ngx_http_request_t *r)
 {
-    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                   "http read blocked");
+    int                n;
+    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 */
 
-    if ((ngx_event_flags & NGX_USE_LEVEL_EVENT)
-        && r->connection->read->active)
-    {
-        if (ngx_del_event(r->connection->read, NGX_READ_EVENT, 0)
-            == NGX_ERROR)
-        {
+    if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && rev->active) {
+
+        if (ngx_del_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) {
             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;
 }
 
 


More information about the nginx-ru mailing list