From 7c09f294bf64ca0234e8e798f4acfc41f7f67e72 Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Mon, 20 Aug 2012 20:32:58 +0200 Subject: [PATCH] added content-length report on http body reading errors --- core/utils.c | 14 ++++++++++---- plugins/python/wsgi_handlers.c | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/utils.c b/core/utils.c index 6c02d361..3a88a49c 100644 --- a/core/utils.c +++ b/core/utils.c @@ -1754,7 +1754,7 @@ int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf) { } if (!ret) { - uwsgi_log("buffering POST data timed-out !!!\n"); + uwsgi_log("buffering POST data to memory timed-out !!! (Content-Length: %llu received: %llu)\n", (unsigned long long) wsgi_req->post_cl, (unsigned long long) wsgi_req->post_cl - post_remains); return 0; } @@ -1765,10 +1765,16 @@ int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf) { len = read(wsgi_req->poll.fd, ptr, post_remains); } - if (len <= 0) { + if (len < 0) { uwsgi_error("read()"); return 0; } + + if (len == 0) { + uwsgi_log("client did not send the whole body: %s (Content-Length: %llu received: %llu)\n", strerror(errno), (unsigned long long) wsgi_req->post_cl, (unsigned long long) wsgi_req->post_cl - post_remains); + return 0; + } + ptr += len; post_remains -= len; } @@ -1867,7 +1873,7 @@ cycle: } if (!ret) { - uwsgi_log("buffering POST data timed-out !!!\n"); + uwsgi_log("buffering POST data to disk timed-out !!! (Content-Length: %llu received: %llu)\n", (unsigned long long) wsgi_req->post_cl, (unsigned long long) wsgi_req->post_cl - post_remains); goto end; } @@ -1894,7 +1900,7 @@ cycle: } if (post_chunk == 0) { - uwsgi_log("client did not send the whole body: %s\n", strerror(errno)); + uwsgi_log("client did not send the whole body: %s (Content-Length: %llu received: %llu)\n", strerror(errno), (unsigned long long) wsgi_req->post_cl, (unsigned long long) wsgi_req->post_cl - post_remains); goto end; } diff --git a/plugins/python/wsgi_handlers.c b/plugins/python/wsgi_handlers.c index 28b98746..d0cc63cc 100644 --- a/plugins/python/wsgi_handlers.c +++ b/plugins/python/wsgi_handlers.c @@ -43,7 +43,7 @@ PyObject *uwsgi_Input_getline(uwsgi_Input *self) { UWSGI_RELEASE_GIL; if (uwsgi_waitfd(wsgi_req->poll.fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]) <= 0) { UWSGI_GET_GIL - return PyErr_Format(PyExc_IOError, "error waiting for wsgi.input data"); + return PyErr_Format(PyExc_IOError, "error waiting for wsgi.input data (readline/getline)"); } if (self->readline_max_size > 0 && self->readline_max_size < UWSGI_PY_READLINE_BUFSIZE) { @@ -54,7 +54,7 @@ PyObject *uwsgi_Input_getline(uwsgi_Input *self) { } if (rlen <= 0) { UWSGI_GET_GIL - return PyErr_Format(PyExc_IOError, "error reading wsgi.input data"); + return PyErr_Format(PyExc_IOError, "error reading wsgi.input data (readline/getline)"); } self->readline_size = rlen; @@ -152,14 +152,14 @@ static PyObject *uwsgi_Input_read(uwsgi_Input *self, PyObject *args) { if (uwsgi_waitfd(self->wsgi_req->poll.fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]) <= 0) { free(tmp_buf); UWSGI_GET_GIL - return PyErr_Format(PyExc_IOError, "error waiting for wsgi.input data"); + return PyErr_Format(PyExc_IOError, "error waiting for wsgi.input data: Content-Length %llu received %llu", (unsigned long long) self->wsgi_req->post_cl, (unsigned long long) self->wsgi_req->post_cl - remains); } rlen = read(self->wsgi_req->poll.fd, tmp_buf+tmp_pos, remains); if (rlen <= 0) { free(tmp_buf); UWSGI_GET_GIL - return PyErr_Format(PyExc_IOError, "error reading wsgi.input data"); + return PyErr_Format(PyExc_IOError, "error reading wsgi.input data: Content-Length %llu received %llu", (unsigned long long) self->wsgi_req->post_cl, (unsigned long long) self->wsgi_req->post_cl - remains); } tmp_pos += rlen; remains -= rlen;