summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2021-11-25 16:58:43 +0300
committerMax Romanov <max.romanov@nginx.com>2021-11-25 16:58:43 +0300
commit0af5f6ddb495902914880f540b44d8c828d945f1 (patch)
tree0eeb5d26365aa2d5e21ac8e0362f17e8b65a604b
parent2bc95990571f82ddfc685fadff4847abff4362e3 (diff)
downloadunit-0af5f6ddb495902914880f540b44d8c828d945f1.tar.gz
unit-0af5f6ddb495902914880f540b44d8c828d945f1.tar.bz2
Fixing access_log structure reference counting.
The reference to the access_log structure is stored in the current nxt_router_conf_t and the global nxt_router_t. When the reference is copied, the reference counter should be adjusted accordingly. This closes #593 issue on GitHub.
-rw-r--r--docs/changes.xml7
-rw-r--r--src/nxt_router.c30
2 files changed, 33 insertions, 4 deletions
diff --git a/docs/changes.xml b/docs/changes.xml
index 41adde1b..c0cc524e 100644
--- a/docs/changes.xml
+++ b/docs/changes.xml
@@ -31,6 +31,13 @@ NGINX Unit updated to 1.27.0.
date="" time=""
packager="Andrei Belov &lt;defan@nginx.com&gt;">
+<change type="bugfix">
+<para>
+the router process crash on reconfiguration if "access_log" was configured
+without listeners.
+</para>
+</change>
+
</changes>
diff --git a/src/nxt_router.c b/src/nxt_router.c
index f718bb6e..52ea0f37 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -210,6 +210,8 @@ static void nxt_router_access_log_ready(nxt_task_t *task,
nxt_port_recv_msg_t *msg, void *data);
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_use(nxt_thread_spinlock_t *lock,
+ nxt_router_access_log_t *access_log);
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,
@@ -1153,7 +1155,13 @@ nxt_router_conf_apply(nxt_task_t *task, void *obj, void *data)
nxt_queue_add(&router->sockets, &updating_sockets);
nxt_queue_add(&router->sockets, &creating_sockets);
- router->access_log = rtcf->access_log;
+ if (router->access_log != rtcf->access_log) {
+ nxt_router_access_log_use(&router->lock, rtcf->access_log);
+
+ nxt_router_access_log_release(task, &router->lock, router->access_log);
+
+ router->access_log = rtcf->access_log;
+ }
nxt_router_conf_ready(task, tmcf);
@@ -1975,9 +1983,7 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
access_log = router->access_log;
if (access_log != NULL && nxt_strstr_eq(&path, &access_log->path)) {
- nxt_thread_spin_lock(&router->lock);
- access_log->count++;
- nxt_thread_spin_unlock(&router->lock);
+ nxt_router_access_log_use(&router->lock, access_log);
} else {
access_log = nxt_malloc(sizeof(nxt_router_access_log_t)
@@ -3932,6 +3938,22 @@ nxt_router_access_log_error(nxt_task_t *task, nxt_port_recv_msg_t *msg,
static void
+nxt_router_access_log_use(nxt_thread_spinlock_t *lock,
+ nxt_router_access_log_t *access_log)
+{
+ if (access_log == NULL) {
+ return;
+ }
+
+ nxt_thread_spin_lock(lock);
+
+ access_log->count++;
+
+ nxt_thread_spin_unlock(lock);
+}
+
+
+static void
nxt_router_access_log_release(nxt_task_t *task, nxt_thread_spinlock_t *lock,
nxt_router_access_log_t *access_log)
{