Fixing 'find & add' racing condition in connected ports hash.

Missing error log messages added.
This commit is contained in:
Max Romanov
2020-04-06 16:52:11 +03:00
parent a49023229e
commit 792ef9d3c7
4 changed files with 29 additions and 32 deletions

View File

@@ -590,17 +590,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)
{
@@ -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);