From 27c1e268563da002e57f34032499efd7543b8b9d Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 8 Apr 2020 15:15:24 +0300 Subject: Controller: eliminated extra control socket's sockaddr copying. --- src/nxt_controller.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'src/nxt_controller.c') diff --git a/src/nxt_controller.c b/src/nxt_controller.c index cc1ed534..ad292421 100644 --- a/src/nxt_controller.c +++ b/src/nxt_controller.c @@ -402,24 +402,14 @@ nxt_controller_conf_send(nxt_task_t *task, nxt_conf_value_t *conf, nxt_int_t nxt_runtime_controller_socket(nxt_task_t *task, nxt_runtime_t *rt) { - nxt_sockaddr_t *sa; nxt_listen_socket_t *ls; - sa = rt->controller_listen; - ls = nxt_mp_alloc(rt->mem_pool, sizeof(nxt_listen_socket_t)); if (ls == NULL) { return NXT_ERROR; } - ls->sockaddr = nxt_sockaddr_create(rt->mem_pool, &sa->u.sockaddr, - sa->socklen, sa->length); - if (ls->sockaddr == NULL) { - return NXT_ERROR; - } - - ls->sockaddr->type = sa->type; - nxt_sockaddr_text(ls->sockaddr); + ls->sockaddr = rt->controller_listen; nxt_listen_socket_remote_size(ls); -- cgit From 555d595f38801685f95f140f85b20f5dcfaa49cd Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 8 Apr 2020 15:15:24 +0300 Subject: Removed unused code related to testing of address binding. --- src/nxt_controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nxt_controller.c') diff --git a/src/nxt_controller.c b/src/nxt_controller.c index ad292421..26f1d53a 100644 --- a/src/nxt_controller.c +++ b/src/nxt_controller.c @@ -431,7 +431,7 @@ nxt_runtime_controller_socket(nxt_task_t *task, nxt_runtime_t *rt) #endif ls->handler = nxt_controller_conn_init; - if (nxt_listen_socket_create(task, ls, 0) != NXT_OK) { + if (nxt_listen_socket_create(task, ls) != NXT_OK) { return NXT_ERROR; } -- cgit From c7f5c1c6641838006088524c2122eae8f9c30431 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 8 Apr 2020 15:15:24 +0300 Subject: Controller: improved handling of unix domain control socket. One of the ways to detect Unit's startup and subsequent readiness to accept commands relies on waiting for the control socket file to be created. Earlier, it was unreliable due to a race condition between the client's connect() and the daemon's listen() calls after the socket's bind() call. Now, unix domain listening sockets are created with a nxt_listen_socket_create() call as follows: s = socket(); unlink("path/to/socket.tmp") bind(s, "path/to/socket.tmp"); listen(s); rename("path/to/socket.tmp", "path/to/socket"); This eliminates a time-lapse when the socket file is already created but nobody is listening on it yet, which therefore prevents the condition described above. Also, it allows reliably detecting whether the socket is being used or simply wasn't cleaned after the daemon stopped abruptly. A successful connection to the socket file means the daemon has been started; otherwise, the file can be overwritten. --- src/nxt_controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nxt_controller.c') diff --git a/src/nxt_controller.c b/src/nxt_controller.c index 26f1d53a..f4c3a00d 100644 --- a/src/nxt_controller.c +++ b/src/nxt_controller.c @@ -431,7 +431,7 @@ nxt_runtime_controller_socket(nxt_task_t *task, nxt_runtime_t *rt) #endif ls->handler = nxt_controller_conn_init; - if (nxt_listen_socket_create(task, ls) != NXT_OK) { + if (nxt_listen_socket_create(task, rt->mem_pool, ls) != NXT_OK) { return NXT_ERROR; } -- cgit From 6bda9b5eeb2b6c99c54f5b314b8eb96d72af3542 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Thu, 16 Apr 2020 17:09:23 +0300 Subject: Using malloc/free for the http fields hash. This is required due to lack of a graceful shutdown: there is a small gap between the runtime's memory pool release and router process's exit. Thus, a worker thread may start processing a request between these two operations, which may result in an http fields hash access and subsequent crash. To simplify issue reproduction, it makes sense to add a 2 sec sleep before exit() in nxt_runtime_exit(). --- src/nxt_controller.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nxt_controller.c') diff --git a/src/nxt_controller.c b/src/nxt_controller.c index f4c3a00d..f9b2cf26 100644 --- a/src/nxt_controller.c +++ b/src/nxt_controller.c @@ -130,14 +130,11 @@ nxt_controller_start(nxt_task_t *task, void *data) nxt_mp_t *mp; nxt_int_t ret; nxt_str_t *json; - nxt_runtime_t *rt; nxt_conf_value_t *conf; nxt_conf_validation_t vldt; nxt_controller_init_t *init; - rt = task->thread->runtime; - - ret = nxt_http_fields_hash(&nxt_controller_fields_hash, rt->mem_pool, + ret = nxt_http_fields_hash(&nxt_controller_fields_hash, nxt_controller_request_fields, nxt_nitems(nxt_controller_request_fields)); -- cgit