]> git.kaiwu.me - nginx.git/commitdiff
close keep-alive connections in the shuting down processes
authorIgor Sysoev <igor@sysoev.ru>
Mon, 19 Mar 2007 13:20:15 +0000 (13:20 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 19 Mar 2007 13:20:15 +0000 (13:20 +0000)
src/core/ngx_connection.h
src/http/ngx_http_request.c
src/os/unix/ngx_process_cycle.c

index 1694dd451427b3cdff1b22349b3ee88e3172e6f5..a2ae690f54617716232efc60018b2a1e68e405c8 100644 (file)
@@ -143,6 +143,9 @@ struct ngx_connection_s {
     unsigned            error:1;
     unsigned            destroyed:1;
 
+    unsigned            idle:1;
+    unsigned            close:1;
+
     unsigned            sendfile:1;
     unsigned            sndlowat:1;
     unsigned            tcp_nodelay:2;   /* ngx_connection_tcp_nodelay_e */
index 96286597b0c4e57cc062da7c8b4234de133a9b63..afc1d644d16846a81effa48d06947c76fb7152c5 100644 (file)
@@ -2032,6 +2032,8 @@ ngx_http_set_keepalive(ngx_http_request_t *r)
     r->http_state = NGX_HTTP_KEEPALIVE_STATE;
 #endif
 
+    c->idle = 1;
+
     if (rev->ready) {
         ngx_http_keepalive_handler(rev);
     }
@@ -2050,7 +2052,7 @@ ngx_http_keepalive_handler(ngx_event_t *rev)
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http keepalive handler");
 
-    if (rev->timedout) {
+    if (rev->timedout || c->close) {
         ngx_http_close_connection(c);
         return;
     }
@@ -2139,6 +2141,8 @@ ngx_http_keepalive_handler(ngx_event_t *rev)
     c->log->handler = ngx_http_log_error;
     c->log->action = "reading client request line";
 
+    c->idle = 0;
+
     ngx_http_init_request(rev);
 }
 
index 1b6a0804cb9ef77e4b06df7156a40c55fde970e9..90993966d006abc8bec4ee6aeafd89e497d940da 100644 (file)
@@ -664,6 +664,8 @@ ngx_master_process_exit(ngx_cycle_t *cycle)
 static void
 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
 {
+    ngx_uint_t         i;
+    ngx_connection_t  *c;
 #if (NGX_THREADS)
     ngx_int_t          n;
     ngx_err_t          err;
@@ -717,12 +719,27 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
 #endif
 
     for ( ;; ) {
-        if (ngx_exiting
-            && ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel)
-        {
-            ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
 
-            ngx_worker_process_exit(cycle);
+        if (ngx_exiting) {
+
+            c = cycle->connections;
+
+            for (i = 0; i < cycle->connection_n; i++) {
+
+                /* THREAD: lock */
+
+                if (c[i].fd != -1 && c[i].idle) {
+                    c[i].close = 1;
+                    c[i].read->handler(c[i].read);
+                }
+            }
+
+            if (ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel)
+            {
+                ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
+
+                ngx_worker_process_exit(cycle);
+            }
         }
 
         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");