This commit is contained in:
wuzhuoquan 2025-02-06 05:31:00 +00:00 committed by GitHub
commit 55e5c7315d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 3 deletions

View File

@ -132,6 +132,13 @@ static ngx_command_t ngx_core_commands[] = {
offsetof(ngx_core_conf_t, shutdown_timeout),
NULL },
{ ngx_string("shutdown_close_idle_connections"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
0,
offsetof(ngx_core_conf_t, shutdown_close_idle_connections),
NULL },
{ ngx_string("working_directory"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
@ -1115,6 +1122,7 @@ ngx_core_module_create_conf(ngx_cycle_t *cycle)
ccf->master = NGX_CONF_UNSET;
ccf->timer_resolution = NGX_CONF_UNSET_MSEC;
ccf->shutdown_timeout = NGX_CONF_UNSET_MSEC;
ccf->shutdown_close_idle_connections = NGX_CONF_UNSET;
ccf->worker_processes = NGX_CONF_UNSET;
ccf->debug_points = NGX_CONF_UNSET;
@ -1144,6 +1152,7 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_value(ccf->master, 1);
ngx_conf_init_msec_value(ccf->timer_resolution, 0);
ngx_conf_init_msec_value(ccf->shutdown_timeout, 0);
ngx_conf_init_value(ccf->shutdown_close_idle_connections, 1);
ngx_conf_init_value(ccf->worker_processes, 1);
ngx_conf_init_value(ccf->debug_points, 0);

View File

@ -89,7 +89,7 @@ struct ngx_cycle_s {
typedef struct {
ngx_flag_t daemon;
ngx_flag_t master;
ngx_flag_t shutdown_close_idle_connections;
ngx_msec_t timer_resolution;
ngx_msec_t shutdown_timeout;
@ -118,7 +118,7 @@ typedef struct {
ngx_array_t env;
char **environment;
ngx_uint_t transparent; /* unsigned transparent:1; */
ngx_uint_t transparent; /* unsigned transparent:1; */
} ngx_core_conf_t;

View File

@ -699,6 +699,8 @@ static void
ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
{
ngx_int_t worker = (intptr_t) data;
ngx_core_conf_t *ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
ngx_core_module);
ngx_process = NGX_PROCESS_WORKER;
ngx_worker = worker;
@ -735,7 +737,11 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
ngx_exiting = 1;
ngx_set_shutdown_timer(cycle);
ngx_close_listening_sockets(cycle);
ngx_close_idle_connections(cycle);
if (ccf->shutdown_close_idle_connections) {
ngx_close_idle_connections(cycle);
} else {
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "shutdown_close_idle_connections is not set, not closing idle connections, waiting for connections to close by keepalive_timeout or last response with connection: close");
}
ngx_event_process_posted(cycle, &ngx_posted_events);
}
}