summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_process.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2020-04-06 16:52:11 +0300
committerMax Romanov <max.romanov@nginx.com>2020-04-06 16:52:11 +0300
commit792ef9d3c71c6843dbbde450a2d6d1ade538f1f3 (patch)
tree5b2c15a2b3d6f7855b0209b74a6d855e30245b17 /src/nxt_process.c
parenta49023229ec0a404665a711fbf35f6b3bf715825 (diff)
downloadunit-792ef9d3c71c6843dbbde450a2d6d1ade538f1f3.tar.gz
unit-792ef9d3c71c6843dbbde450a2d6d1ade538f1f3.tar.bz2
Fixing 'find & add' racing condition in connected ports hash.
Missing error log messages added.
Diffstat (limited to '')
-rw-r--r--src/nxt_process.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/nxt_process.c b/src/nxt_process.c
index 035f747f..4179844b 100644
--- a/src/nxt_process.c
+++ b/src/nxt_process.c
@@ -591,17 +591,6 @@ nxt_process_close_ports(nxt_task_t *task, nxt_process_t *process)
void
-nxt_process_connected_port_add(nxt_process_t *process, nxt_port_t *port)
-{
- nxt_thread_mutex_lock(&process->cp_mutex);
-
- nxt_port_hash_add(&process->connected_ports, port);
-
- nxt_thread_mutex_unlock(&process->cp_mutex);
-}
-
-
-void
nxt_process_connected_port_remove(nxt_process_t *process, nxt_port_t *port)
{
nxt_thread_mutex_lock(&process->cp_mutex);
@@ -613,14 +602,17 @@ nxt_process_connected_port_remove(nxt_process_t *process, nxt_port_t *port)
nxt_port_t *
-nxt_process_connected_port_find(nxt_process_t *process, nxt_pid_t pid,
- nxt_port_id_t port_id)
+nxt_process_connected_port_find_add(nxt_process_t *process, nxt_port_t *port)
{
nxt_port_t *res;
nxt_thread_mutex_lock(&process->cp_mutex);
- res = nxt_port_hash_find(&process->connected_ports, pid, port_id);
+ res = nxt_port_hash_find(&process->connected_ports, port->pid, port->id);
+
+ if (nxt_slow_path(res == NULL)) {
+ nxt_port_hash_add(&process->connected_ports, port);
+ }
nxt_thread_mutex_unlock(&process->cp_mutex);