From 9fe6e75d355266024f67a5611120c3c97557be14 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Thu, 20 Sep 2018 16:16:32 +0300 Subject: [PATCH] Preventing port from release in asynchronous operations. Router reconfiguration may lead to starting new application processes, opening listen ports etc. These actions are asynchronous and require message exchange with master process. Router stores reference for controller (response) port in structure associated with reconfiguration process (tmcf). The port used to provide reconfiguration response (either success or failed) to controller. This commit increases response port use counter to make sure port structure not freed while router waits for result of asynchronous operations. --- src/nxt_router.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/nxt_router.c b/src/nxt_router.c index 21a7b4d7..139b2c4c 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -874,6 +874,14 @@ nxt_router_conf_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) msg->port_msg.pid, msg->port_msg.reply_port); + if (nxt_slow_path(tmcf->port == NULL)) { + nxt_alert(task, "reply port not found"); + + return; + } + + nxt_port_use(task, tmcf->port, 1); + b = nxt_buf_chk_make_plain(tmcf->router_conf->mem_pool, msg->buf, msg->size); if (nxt_slow_path(b == NULL)) { @@ -1204,6 +1212,10 @@ nxt_router_conf_send(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type) { nxt_port_socket_write(task, tmcf->port, type, -1, tmcf->stream, 0, NULL); + + nxt_port_use(task, tmcf->port, -1); + + tmcf->port = NULL; }