summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_router.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-04-19 19:48:58 +0300
committerValentin Bartenev <vbart@nginx.com>2018-04-19 19:48:58 +0300
commita20830ff554a10094894e825ef9124c4a81745b6 (patch)
treec247972e1c0e86c207ba0e78d2b92908323fa535 /src/nxt_router.c
parentda22c2ca96d9484eb4e95536fd6276967868114e (diff)
downloadunit-a20830ff554a10094894e825ef9124c4a81745b6.tar.gz
unit-a20830ff554a10094894e825ef9124c4a81745b6.tar.bz2
Router: fixed race condition while access log reopening.
In order to reopen access log, the router process creates a memory pool and allocates a buffer to send RPC message for the main process. Previously, the memory pool was destroyed when RPC response handler was called. It appeared, that the buffer completion handler could be not triggered by that time and still remained in a queue. Now the memory pool is destroyed only after both events are happen.
Diffstat (limited to 'src/nxt_router.c')
-rw-r--r--src/nxt_router.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/nxt_router.c b/src/nxt_router.c
index 459c2a9d..ddedaa59 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -220,6 +220,8 @@ static void nxt_router_access_log_error(nxt_task_t *task,
nxt_port_recv_msg_t *msg, void *data);
static void nxt_router_access_log_release(nxt_task_t *task,
nxt_thread_spinlock_t *lock, nxt_router_access_log_t *access_log);
+static void nxt_router_access_log_reopen_completion(nxt_task_t *task, void *obj,
+ void *data);
static void nxt_router_access_log_reopen_ready(nxt_task_t *task,
nxt_port_recv_msg_t *msg, void *data);
static void nxt_router_access_log_reopen_error(nxt_task_t *task,
@@ -2965,6 +2967,8 @@ nxt_router_access_log_reopen_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
goto fail;
}
+ b->completion_handler = nxt_router_access_log_reopen_completion;
+
nxt_buf_cpystr(b, &access_log->path);
*b->mem.free++ = '\0';
@@ -2988,6 +2992,8 @@ nxt_router_access_log_reopen_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
goto fail;
}
+ nxt_mp_retain(mp);
+
return;
fail:
@@ -2997,6 +3003,19 @@ fail:
static void
+nxt_router_access_log_reopen_completion(nxt_task_t *task, void *obj, void *data)
+{
+ nxt_mp_t *mp;
+ nxt_buf_t *b;
+
+ b = obj;
+ mp = b->data;
+
+ nxt_mp_release(mp);
+}
+
+
+static void
nxt_router_access_log_reopen_ready(nxt_task_t *task, nxt_port_recv_msg_t *msg,
void *data)
{
@@ -3016,7 +3035,7 @@ nxt_router_access_log_reopen_ready(nxt_task_t *task, nxt_port_recv_msg_t *msg,
}
nxt_fd_close(msg->fd);
- nxt_mp_destroy(reopen->mem_pool);
+ nxt_mp_release(reopen->mem_pool);
}
@@ -3028,7 +3047,7 @@ nxt_router_access_log_reopen_error(nxt_task_t *task, nxt_port_recv_msg_t *msg,
reopen = data;
- nxt_mp_destroy(reopen->mem_pool);
+ nxt_mp_release(reopen->mem_pool);
}