close keep-alive connections in the shuting down processes

This commit is contained in:
Igor Sysoev 2007-03-19 13:20:15 +00:00
parent e1f43ce292
commit 4ddeff4956
3 changed files with 30 additions and 6 deletions

View 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 */

View 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);
}

View 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");