summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_controller.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2017-08-30 03:09:06 +0300
committerValentin Bartenev <vbart@nginx.com>2017-08-30 03:09:06 +0300
commite21dbf89e6d5569d1c9a93f41a21bcc240c64cf3 (patch)
treea1fc9ecfa69ada6ba42f319f3cf50d048aa950c8 /src/nxt_controller.c
parentcdc7e4479ff5aa08df0857a13a7acd7a00b79c89 (diff)
downloadunit-e21dbf89e6d5569d1c9a93f41a21bcc240c64cf3.tar.gz
unit-e21dbf89e6d5569d1c9a93f41a21bcc240c64cf3.tar.bz2
Controller: correct handling of missing router port.
There's no router port if the router process is just crashed or hasn't started yet.
Diffstat (limited to 'src/nxt_controller.c')
-rw-r--r--src/nxt_controller.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/src/nxt_controller.c b/src/nxt_controller.c
index 00742607..236d5265 100644
--- a/src/nxt_controller.c
+++ b/src/nxt_controller.c
@@ -646,8 +646,16 @@ nxt_controller_process_request(nxt_task_t *task, nxt_controller_request_t *req)
req->conf.root = value;
req->conf.pool = mp;
- if (nxt_controller_conf_apply(task, req) != NXT_OK) {
+ rc = nxt_controller_conf_apply(task, req);
+
+ if (nxt_slow_path(rc != NXT_OK)) {
nxt_mp_destroy(mp);
+
+ if (rc == NXT_DECLINED) {
+ goto no_router;
+ }
+
+ /* rc == NXT_ERROR */
goto alloc_fail;
}
@@ -705,8 +713,16 @@ nxt_controller_process_request(nxt_task_t *task, nxt_controller_request_t *req)
req->conf.root = value;
req->conf.pool = mp;
- if (nxt_controller_conf_apply(task, req) != NXT_OK) {
+ rc = nxt_controller_conf_apply(task, req);
+
+ if (nxt_slow_path(rc != NXT_OK)) {
nxt_mp_destroy(mp);
+
+ if (rc == NXT_DECLINED) {
+ goto no_router;
+ }
+
+ /* rc == NXT_ERROR */
goto alloc_fail;
}
@@ -720,15 +736,6 @@ nxt_controller_process_request(nxt_task_t *task, nxt_controller_request_t *req)
nxt_controller_response(task, req, &resp);
return;
-alloc_fail:
-
- resp.status = 500;
- resp.title = (u_char *) "Memory allocation failed.";
- resp.offset = -1;
-
- nxt_controller_response(task, req, &resp);
- return;
-
not_found:
resp.status = 404;
@@ -746,6 +753,24 @@ invalid_conf:
nxt_controller_response(task, req, &resp);
return;
+
+alloc_fail:
+
+ resp.status = 500;
+ resp.title = (u_char *) "Memory allocation failed.";
+ resp.offset = -1;
+
+ nxt_controller_response(task, req, &resp);
+ return;
+
+no_router:
+
+ resp.status = 500;
+ resp.title = (u_char *) "Router process isn't available.";
+ resp.offset = -1;
+
+ nxt_controller_response(task, req, &resp);
+ return;
}
@@ -762,6 +787,11 @@ nxt_controller_conf_apply(nxt_task_t *task, nxt_controller_request_t *req)
rt = task->thread->runtime;
router_port = rt->port_by_type[NXT_PROCESS_ROUTER];
+
+ if (nxt_slow_path(router_port == NULL)) {
+ return NXT_DECLINED;
+ }
+
controller_port = rt->port_by_type[NXT_PROCESS_CONTROLLER];
size = nxt_conf_json_length(req->conf.root, NULL);