close keep-alive connections in the shuting down processes
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h
index 1694dd4..a2ae690 100644
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -143,6 +143,9 @@
     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 */
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 9628659..afc1d64 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -2032,6 +2032,8 @@
     r->http_state = NGX_HTTP_KEEPALIVE_STATE;
 #endif
 
+    c->idle = 1;
+
     if (rev->ready) {
         ngx_http_keepalive_handler(rev);
     }
@@ -2050,7 +2052,7 @@
 
     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 @@
     c->log->handler = ngx_http_log_error;
     c->log->action = "reading client request line";
 
+    c->idle = 0;
+
     ngx_http_init_request(rev);
 }
 
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 1b6a080..9099396 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -664,6 +664,8 @@
 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 @@
 #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");