diff --git a/loop.c b/loop.c index 1d7aa95b..66a8477f 100644 --- a/loop.c +++ b/loop.c @@ -85,12 +85,10 @@ void *simple_loop(void *arg1) { continue; } - uwsgi_log("accepted\n"); if (wsgi_req_recv(wsgi_req)) { continue; } - uwsgi_close_request(wsgi_req); } diff --git a/multi.xml b/multi.xml index fe6997a2..8dec64e0 100644 --- a/multi.xml +++ b/multi.xml @@ -10,10 +10,12 @@ - 4 + 8 + TRAC_ENV=utrac diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index aadce342..a9ea0056 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -158,13 +158,14 @@ PyObject *py_uwsgi_close(PyObject * self, PyObject * args) { PyObject *py_uwsgi_signal(PyObject * self, PyObject * args) { char uwsgi_signal; + ssize_t rlen; if (!PyArg_ParseTuple(args, "B:signal", &uwsgi_signal)) { return NULL; } uwsgi_log("sending %d to master\n", uwsgi_signal); - write(uwsgi.workers[uwsgi.mywid].pipe[1], &uwsgi_signal, 1); + rlen = write(uwsgi.workers[uwsgi.mywid].pipe[1], &uwsgi_signal, 1); Py_INCREF(Py_None); return Py_None; diff --git a/plugins/python/wsgi_handlers.c b/plugins/python/wsgi_handlers.c index 3755f893..dbf93809 100644 --- a/plugins/python/wsgi_handlers.c +++ b/plugins/python/wsgi_handlers.c @@ -212,6 +212,12 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { } + if (wsgi_req->uh.modifier2 == 4) { + // for persistent connections + uwsgi_log("LEAVE OPEN\n"); + wsgi_req->leave_open = 1; + } + if (wsgi_req->protocol_len < 5) { @@ -274,10 +280,6 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { } } - if (wsgi_req->uh.modifier2 == 4) { - // for persistent connections - wsgi_req->leave_open = 1; - } if (uwsgi.post_buffering > 0 && wsgi_req->post_cl > (size_t) uwsgi.post_buffering) { @@ -292,7 +294,9 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { } + uwsgi_log("before subhandler %d\n", wsgi_req->leave_open); wsgi_req->async_result = wi->request_subhandler(wsgi_req, wi); + uwsgi_log("after subhandler %d\n", wsgi_req->leave_open); if (wsgi_req->async_result) { diff --git a/plugins/python/wsgi_subhandler.c b/plugins/python/wsgi_subhandler.c index 1fd900d8..107e771a 100644 --- a/plugins/python/wsgi_subhandler.c +++ b/plugins/python/wsgi_subhandler.c @@ -204,6 +204,7 @@ clear: } if (wsgi_req->async_post && !wsgi_req->fd_closed) { if (!wsgi_req->leave_open) { + uwsgi_log("FCLOSE()\n"); fclose(wsgi_req->async_post); } if (!uwsgi.post_buffering || wsgi_req->post_cl <= (size_t) uwsgi.post_buffering) { diff --git a/protocol.c b/protocol.c index d5a7f47f..815f4873 100644 --- a/protocol.c +++ b/protocol.c @@ -202,11 +202,18 @@ ssize_t uwsgi_send_message(int fd, uint8_t modifier1, uint8_t modifier2, char *m int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header *uh, char *buffer) { int rlen, i; + struct wsgi_request *wsgi_req = (struct wsgi_request *) uh; if (!timeout) timeout = 1; /* first 4 byte header */ - uwsgi_log("poll()\n"); - rlen = poll(upoll, 1, timeout * 1000); + if (wsgi_req->leave_open) { + // wait for max 1 hour for the first request + uwsgi_log("ready to accept a new request on connection %d\n", wsgi_req->poll.fd); + rlen = poll(upoll, 1, 3600 * 1000); + } + else { + rlen = poll(upoll, 1, timeout * 1000); + } if (rlen < 0) { uwsgi_error("poll()"); exit(1); @@ -245,6 +252,7 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header else if (rlen <= 0) { uwsgi_log( "invalid request header size: %d...skip\n", rlen); close(upoll->fd); + wsgi_req->leave_open = 0; return 0; } /* big endian ? */ diff --git a/utils.c b/utils.c index 9f8dc390..6ce8988b 100644 --- a/utils.c +++ b/utils.c @@ -348,11 +348,17 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) { get_memusage(); + uwsgi_log("LEAVE_OPEN: %d\n", wsgi_req->leave_open); // close the connection with the webserver if (!wsgi_req->fd_closed && !wsgi_req->leave_open) { // NOTE, if we close the socket before receiving eventually sent data, socket layer will send a RST + uwsgi_log("CLOSE()\n"); close(wsgi_req->poll.fd); } + else if (wsgi_req->leave_open) { + // send OOB data to signal peer of EOS + send(wsgi_req->poll.fd, "\0", 1, MSG_OOB); + } uwsgi.workers[0].requests++; uwsgi.workers[uwsgi.mywid].requests++; @@ -436,6 +442,7 @@ int wsgi_req_recv(struct wsgi_request *wsgi_req) { } wsgi_req->async_status = uwsgi.p[wsgi_req->uh.modifier1]->request(wsgi_req); + uwsgi_log("leave_open after request %d\n", wsgi_req->leave_open); return 0; }