summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2020-07-23 14:25:21 +0300
committerMax Romanov <max.romanov@nginx.com>2020-07-23 14:25:21 +0300
commit9641fb0ef1d708bb9ec8c00ea5ec694829e4fd67 (patch)
treed282d8bd28db83747848a8b76cba5052b16af081
parentd3c8d622807c058c0f8aff6714cf40585b08faa5 (diff)
downloadunit-9641fb0ef1d708bb9ec8c00ea5ec694829e4fd67.tar.gz
unit-9641fb0ef1d708bb9ec8c00ea5ec694829e4fd67.tar.bz2
Fixing various router crashes on exit caused by runtime pool free.
Currently, the router exits without waiting for the worker threads to stop. There is a short gap between the runtime memory pool's free and the exit, during which a worker thread may try to access a runtime structure. In turn, this may cause a crash. For now, it is better to keep this memory allocated.
Diffstat (limited to '')
-rw-r--r--src/nxt_runtime.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c
index 5aa061dd..694ce74d 100644
--- a/src/nxt_runtime.c
+++ b/src/nxt_runtime.c
@@ -527,7 +527,7 @@ nxt_runtime_stop_all_processes(nxt_task_t *task, nxt_runtime_t *rt)
static void
nxt_runtime_exit(nxt_task_t *task, void *obj, void *data)
{
- int status;
+ int status, engine_count;
nxt_runtime_t *rt;
nxt_process_t *process;
nxt_event_engine_t *engine;
@@ -571,14 +571,25 @@ nxt_runtime_exit(nxt_task_t *task, void *obj, void *data)
} nxt_runtime_process_loop;
- if (rt->port_by_type[rt->type] != NULL) {
- nxt_port_use(task, rt->port_by_type[rt->type], -1);
- }
+ status = rt->status;
- nxt_thread_mutex_destroy(&rt->processes_mutex);
+ engine_count = 0;
- status = rt->status;
- nxt_mp_destroy(rt->mem_pool);
+ nxt_queue_each(engine, &rt->engines, nxt_event_engine_t, link) {
+
+ engine_count++;
+
+ } nxt_queue_loop;
+
+ if (engine_count <= 1) {
+ if (rt->port_by_type[rt->type] != NULL) {
+ nxt_port_use(task, rt->port_by_type[rt->type], -1);
+ }
+
+ nxt_thread_mutex_destroy(&rt->processes_mutex);
+
+ nxt_mp_destroy(rt->mem_pool);
+ }
nxt_debug(task, "exit: %d", status);