Making port fd blocking on app side and non-blocking in Unit.

This issue was introduced in libunit commit (e0f0cd7d244a).  All port
sockets in application should be in blocking mode whereas Unit itself
operates non-blocking sockets.

Having non-blocking sockets in application may cause send error during
intensive response packets generation.

See https://mailman.nginx.org/pipermail/unit/2018-October/000080.html.
This commit is contained in:
Max Romanov
2018-10-02 19:46:06 +03:00
parent d54d806c52
commit cb1b074493
2 changed files with 12 additions and 1 deletions

View File

@@ -276,6 +276,8 @@ nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
nxt_process_use(task, process, -1); nxt_process_use(task, process, -1);
nxt_fd_nonblocking(task, msg->fd);
port->pair[0] = -1; port->pair[0] = -1;
port->pair[1] = msg->fd; port->pair[1] = msg->fd;
port->max_size = new_port_msg->max_size; port->max_size = new_port_msg->max_size;

View File

@@ -510,7 +510,7 @@ int
nxt_unit_process_msg(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id, nxt_unit_process_msg(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id,
void *buf, size_t buf_size, void *oob, size_t oob_size) void *buf, size_t buf_size, void *oob, size_t oob_size)
{ {
int fd, rc; int fd, rc, nb;
pid_t pid; pid_t pid;
nxt_queue_t incoming_buf; nxt_queue_t incoming_buf;
struct cmsghdr *cm; struct cmsghdr *cm;
@@ -611,6 +611,15 @@ nxt_unit_process_msg(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id,
port_msg->stream, (int) new_port_msg->pid, port_msg->stream, (int) new_port_msg->pid,
(int) new_port_msg->id, fd); (int) new_port_msg->id, fd);
nb = 0;
if (nxt_slow_path(ioctl(fd, FIONBIO, &nb) == -1)) {
nxt_unit_alert(ctx, "#%"PRIu32": new_port: ioctl(%d, FIONBIO, 0) "
"failed: %s (%d)", fd, strerror(errno), errno);
goto fail;
}
nxt_unit_port_id_init(&new_port.id, new_port_msg->pid, nxt_unit_port_id_init(&new_port.id, new_port_msg->pid,
new_port_msg->id); new_port_msg->id);