summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2018-04-05 17:20:26 +0300
committerMax Romanov <max.romanov@nginx.com>2018-04-05 17:20:26 +0300
commit2f3b9d458328c7c96f91259c1892810c16cbccdd (patch)
tree02f9b4e73a698556f80f2eb0940f79544e89036e /src
parentd748f74f2b68c6c36d4d41cd39223e842e2a3441 (diff)
downloadunit-2f3b9d458328c7c96f91259c1892810c16cbccdd.tar.gz
unit-2f3b9d458328c7c96f91259c1892810c16cbccdd.tar.bz2
Handling error return from application 'run()' function.
Server error response generated or connection closed.
Diffstat (limited to '')
-rw-r--r--src/nxt_application.c8
-rw-r--r--src/nxt_router.c10
2 files changed, 14 insertions, 4 deletions
diff --git a/src/nxt_application.c b/src/nxt_application.c
index fba20985..061bc220 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -390,6 +390,7 @@ void
nxt_app_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
{
size_t dump_size;
+ nxt_int_t res;
nxt_buf_t *b;
nxt_port_t *port;
nxt_app_rmsg_t rmsg = { msg->buf };
@@ -417,7 +418,12 @@ nxt_app_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
wmsg.buf = &wmsg.write;
wmsg.stream = msg->port_msg.stream;
- nxt_app->run(task, &rmsg, &wmsg);
+ res = nxt_app->run(task, &rmsg, &wmsg);
+
+ if (nxt_slow_path(res != NXT_OK)) {
+ nxt_port_socket_write(task, port, NXT_PORT_MSG_RPC_ERROR, -1,
+ msg->port_msg.stream, 0, NULL);
+ }
}
diff --git a/src/nxt_router.c b/src/nxt_router.c
index 5b638ed0..947f7235 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -2268,8 +2268,9 @@ nxt_router_engine_post(nxt_event_engine_t *engine, nxt_work_t *jobs)
static nxt_port_handlers_t nxt_router_app_port_handlers = {
- .mmap = nxt_port_mmap_handler,
- .data = nxt_port_rpc_handler,
+ .rpc_error = nxt_port_rpc_handler,
+ .mmap = nxt_port_mmap_handler,
+ .data = nxt_port_rpc_handler,
};
@@ -2808,7 +2809,10 @@ nxt_router_response_error_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg,
}
}
- nxt_http_request_error(task, rc->ap->request, NXT_HTTP_SERVICE_UNAVAILABLE);
+ if (rc->ap != NULL) {
+ nxt_http_request_error(task, rc->ap->request,
+ NXT_HTTP_SERVICE_UNAVAILABLE);
+ }
nxt_router_rc_unlink(task, rc);
}