Mercurial > hg > nginx-quic
comparison src/core/ngx_cycle.c @ 6930:97c99bb43737
Introduced worker_shutdown_timeout.
The directive configures a timeout to be used when gracefully shutting down
worker processes. When the timer expires, nginx will try to close all
the connections currently open to facilitate shutdown.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 07 Mar 2017 18:51:16 +0300 |
parents | 30b6f1ff192b |
children | 99c87770b81b |
comparison
equal
deleted
inserted
replaced
6929:3069dd358ba2 | 6930:97c99bb43737 |
---|---|
13 static void ngx_destroy_cycle_pools(ngx_conf_t *conf); | 13 static void ngx_destroy_cycle_pools(ngx_conf_t *conf); |
14 static ngx_int_t ngx_init_zone_pool(ngx_cycle_t *cycle, | 14 static ngx_int_t ngx_init_zone_pool(ngx_cycle_t *cycle, |
15 ngx_shm_zone_t *shm_zone); | 15 ngx_shm_zone_t *shm_zone); |
16 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log); | 16 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log); |
17 static void ngx_clean_old_cycles(ngx_event_t *ev); | 17 static void ngx_clean_old_cycles(ngx_event_t *ev); |
18 static void ngx_shutdown_timer_handler(ngx_event_t *ev); | |
18 | 19 |
19 | 20 |
20 volatile ngx_cycle_t *ngx_cycle; | 21 volatile ngx_cycle_t *ngx_cycle; |
21 ngx_array_t ngx_old_cycles; | 22 ngx_array_t ngx_old_cycles; |
22 | 23 |
23 static ngx_pool_t *ngx_temp_pool; | 24 static ngx_pool_t *ngx_temp_pool; |
24 static ngx_event_t ngx_cleaner_event; | 25 static ngx_event_t ngx_cleaner_event; |
26 static ngx_event_t ngx_shutdown_event; | |
25 | 27 |
26 ngx_uint_t ngx_test_config; | 28 ngx_uint_t ngx_test_config; |
27 ngx_uint_t ngx_dump_config; | 29 ngx_uint_t ngx_dump_config; |
28 ngx_uint_t ngx_quiet_mode; | 30 ngx_uint_t ngx_quiet_mode; |
29 | 31 |
1331 ngx_destroy_pool(ngx_temp_pool); | 1333 ngx_destroy_pool(ngx_temp_pool); |
1332 ngx_temp_pool = NULL; | 1334 ngx_temp_pool = NULL; |
1333 ngx_old_cycles.nelts = 0; | 1335 ngx_old_cycles.nelts = 0; |
1334 } | 1336 } |
1335 } | 1337 } |
1338 | |
1339 | |
1340 void | |
1341 ngx_set_shutdown_timer(ngx_cycle_t *cycle) | |
1342 { | |
1343 ngx_core_conf_t *ccf; | |
1344 | |
1345 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
1346 | |
1347 if (ccf->shutdown_timeout) { | |
1348 ngx_shutdown_event.handler = ngx_shutdown_timer_handler; | |
1349 ngx_shutdown_event.data = cycle; | |
1350 ngx_shutdown_event.log = cycle->log; | |
1351 ngx_shutdown_event.cancelable = 1; | |
1352 | |
1353 ngx_add_timer(&ngx_shutdown_event, ccf->shutdown_timeout); | |
1354 } | |
1355 } | |
1356 | |
1357 | |
1358 static void | |
1359 ngx_shutdown_timer_handler(ngx_event_t *ev) | |
1360 { | |
1361 ngx_uint_t i; | |
1362 ngx_cycle_t *cycle; | |
1363 ngx_connection_t *c; | |
1364 | |
1365 cycle = ev->data; | |
1366 | |
1367 c = cycle->connections; | |
1368 | |
1369 for (i = 0; i < cycle->connection_n; i++) { | |
1370 | |
1371 if (c[i].fd == (ngx_socket_t) -1 | |
1372 || c[i].read == NULL | |
1373 || c[i].read->accept | |
1374 || c[i].read->channel | |
1375 || c[i].read->resolver) | |
1376 { | |
1377 continue; | |
1378 } | |
1379 | |
1380 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, | |
1381 "*%uA shutdown timeout", c[i].number); | |
1382 | |
1383 c[i].close = 1; | |
1384 c[i].error = 1; | |
1385 | |
1386 c[i].read->handler(c[i].read); | |
1387 } | |
1388 } |