diff --git a/plugins/python/pump_subhandler.c b/plugins/python/pump_subhandler.c index 94b50670..03d4d291 100644 --- a/plugins/python/pump_subhandler.c +++ b/plugins/python/pump_subhandler.c @@ -218,7 +218,9 @@ int uwsgi_response_subhandler_pump(struct wsgi_request *wsgi_req) { goto clear; } - uwsgi_response_prepare_headers(wsgi_req, sc, 3); + if (uwsgi_response_prepare_headers(wsgi_req, sc, 3)) { + uwsgi_log("unable to prepare response headers\n"); + } PyObject *hhkey, *hhvalue; #ifdef UWSGI_PYTHON_OLD @@ -237,12 +239,12 @@ int uwsgi_response_subhandler_pump(struct wsgi_request *wsgi_req) { for(i=0;iasync_placeholder), PyString_Size(wsgi_req->async_placeholder)); UWSGI_GET_GIL + uwsgi_py_check_write_errors { + uwsgi_py_write_exception(wsgi_req); + } goto clear; } #ifdef PYTHREE @@ -263,6 +268,9 @@ int uwsgi_response_subhandler_pump(struct wsgi_request *wsgi_req) { UWSGI_RELEASE_GIL uwsgi_response_sendfile_do(wsgi_req, wsgi_req->sendfile_fd, 0, 0); UWSGI_GET_GIL + uwsgi_py_check_write_errors { + uwsgi_py_write_exception(wsgi_req); + } goto clear; } @@ -301,6 +309,11 @@ int uwsgi_response_subhandler_pump(struct wsgi_request *wsgi_req) { UWSGI_RELEASE_GIL uwsgi_response_write_body_do(wsgi_req, PyString_AsString(pychunk), PyString_Size(pychunk)); UWSGI_GET_GIL + uwsgi_py_check_write_errors { + uwsgi_py_write_exception(wsgi_req); + Py_DECREF(pychunk); + goto clear; + } } diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 220246e4..c2d9b8a1 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -887,7 +887,6 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) { UWSGI_RELEASE_GIL uwsgi_response_sendfile_do(wsgi_req, wsgi_req->sendfile_fd, wsgi_req->sendfile_fd_pos, wsgi_req->sendfile_fd_size); UWSGI_GET_GIL - // revert to old values wsgi_req->sendfile_fd = tmp_fd; wsgi_req->sendfile_fd_size = tmp_filesize; @@ -896,6 +895,12 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) { close(fd); + + uwsgi_py_check_write_errors { + uwsgi_py_write_exception(wsgi_req); + return NULL; + } + Py_INCREF(Py_True); return Py_True; diff --git a/plugins/python/web3_subhandler.c b/plugins/python/web3_subhandler.c index 5b2a4167..9047a8e9 100644 --- a/plugins/python/web3_subhandler.c +++ b/plugins/python/web3_subhandler.c @@ -170,7 +170,7 @@ int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) { char *content = PyString_AsString(wsgi_req->async_placeholder); size_t content_len = PyString_Size(wsgi_req->async_placeholder); UWSGI_RELEASE_GIL - wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len); + uwsgi_response_write_body_do(wsgi_req, content, content_len); UWSGI_GET_GIL uwsgi_py_check_write_errors { uwsgi_py_write_exception(wsgi_req); @@ -213,7 +213,7 @@ int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) { char *content = PyString_AsString(pychunk); size_t content_len = PyString_Size(pychunk); UWSGI_RELEASE_GIL - wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len); + uwsgi_response_write_body_do(wsgi_req, content, content_len); UWSGI_GET_GIL uwsgi_py_check_write_errors { uwsgi_py_write_exception(wsgi_req); diff --git a/plugins/python/wsgi_handlers.c b/plugins/python/wsgi_handlers.c index 697895bb..a9f77e75 100644 --- a/plugins/python/wsgi_handlers.c +++ b/plugins/python/wsgi_handlers.c @@ -498,7 +498,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { // LOCK THIS PART uwsgi_500(wsgi_req); - uwsgi_response_write_headers_do(wsgi_req); + if (uwsgi_response_write_headers_do(wsgi_req)) goto clear; /* sorry that is a hack to avoid the rewrite of PyErr_Print diff --git a/plugins/python/wsgi_subhandler.c b/plugins/python/wsgi_subhandler.c index 123c5f64..ad2926d4 100644 --- a/plugins/python/wsgi_subhandler.c +++ b/plugins/python/wsgi_subhandler.c @@ -173,6 +173,9 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) { UWSGI_RELEASE_GIL uwsgi_response_sendfile_do(wsgi_req, wsgi_req->sendfile_fd, 0, 0); UWSGI_GET_GIL + uwsgi_py_check_write_errors { + uwsgi_py_write_exception(wsgi_req); + } goto clear; } @@ -228,6 +231,11 @@ exception: UWSGI_RELEASE_GIL uwsgi_response_sendfile_do(wsgi_req, wsgi_req->sendfile_fd, 0, 0); UWSGI_GET_GIL + uwsgi_py_check_write_errors { + uwsgi_py_write_exception(wsgi_req); + Py_DECREF(pychunk); + goto clear; + } }