summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2019-09-30 16:39:08 +0300
committerMax Romanov <max.romanov@nginx.com>2019-09-30 16:39:08 +0300
commitf2b280aa0c1e4838c56c9960c717e975a938b1d1 (patch)
tree878e573da93921079866f1f6afc36b3225c0c07c
parentf2c0f2899a5c7b853fee716c53795db3b098727a (diff)
downloadunit-f2b280aa0c1e4838c56c9960c717e975a938b1d1.tar.gz
unit-f2b280aa0c1e4838c56c9960c717e975a938b1d1.tar.bz2
Fixed exiting if a signal arrives during discovery.
When Unit starts, the main process waits for module discovery message for a while. If a QUIT signal arrives at this time, the router and controller processes created by main and Unit stay running. Also, the main process doesn't stop them after the second QUIT signal is received in this case.
-rw-r--r--src/nxt_main_process.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c
index b9e7ab96..85685fbc 100644
--- a/src/nxt_main_process.c
+++ b/src/nxt_main_process.c
@@ -1014,52 +1014,50 @@ nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid)
nxt_process_close_ports(task, process);
- if (!nxt_exiting) {
- nxt_runtime_process_each(rt, process) {
-
- if (process->pid == nxt_pid
- || process->pid == pid
- || nxt_queue_is_empty(&process->ports))
- {
- continue;
- }
-
- port = nxt_process_port_first(process);
+ if (nxt_exiting) {
+ if (rt->nprocesses <= 2) {
+ nxt_runtime_quit(task, 0);
+ }
- if (nxt_proc_remove_notify_matrix[ptype][port->type] == 0) {
- continue;
- }
+ return;
+ }
- buf = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool,
- sizeof(pid));
- if (nxt_slow_path(buf == NULL)) {
- continue;
- }
+ nxt_runtime_process_each(rt, process) {
- buf->mem.free = nxt_cpymem(buf->mem.free, &pid, sizeof(pid));
+ if (process->pid == nxt_pid
+ || process->pid == pid
+ || nxt_queue_is_empty(&process->ports))
+ {
+ continue;
+ }
- nxt_port_socket_write(task, port, NXT_PORT_MSG_REMOVE_PID,
- -1, init->stream, 0, buf);
- } nxt_runtime_process_loop;
- }
+ port = nxt_process_port_first(process);
- if (nxt_exiting) {
+ if (nxt_proc_remove_notify_matrix[ptype][port->type] == 0) {
+ continue;
+ }
- if (rt->nprocesses == 2) {
- nxt_runtime_quit(task, 0);
+ buf = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool,
+ sizeof(pid));
+ if (nxt_slow_path(buf == NULL)) {
+ continue;
}
- } else if (init != NULL) {
- if (init->restart != NULL) {
- if (init->type == NXT_PROCESS_ROUTER) {
- nxt_main_stop_worker_processes(task, rt);
- }
+ buf->mem.free = nxt_cpymem(buf->mem.free, &pid, sizeof(pid));
- init->restart(task, rt, init);
+ nxt_port_socket_write(task, port, NXT_PORT_MSG_REMOVE_PID,
+ -1, init->stream, 0, buf);
+ } nxt_runtime_process_loop;
- } else {
- nxt_free(init);
+ if (init->restart != NULL) {
+ if (init->type == NXT_PROCESS_ROUTER) {
+ nxt_main_stop_worker_processes(task, rt);
}
+
+ init->restart(task, rt, init);
+
+ } else {
+ nxt_free(init);
}
}
}
@@ -1313,6 +1311,11 @@ nxt_main_port_modules_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
return;
}
+ if (nxt_exiting) {
+ nxt_debug(task, "ignoring discovered modules, exiting");
+ return;
+ }
+
port = nxt_runtime_port_find(task->thread->runtime, msg->port_msg.pid,
msg->port_msg.reply_port);