Skip to content

Commit

Permalink
Merge pull request #1411 from a-feld/master
Browse files Browse the repository at this point in the history
Fix SystemError exception when async_args PyTuple is reused. #1408
  • Loading branch information
unbit committed Dec 5, 2016
2 parents f262899 + e0624ad commit e61e3e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
7 changes: 6 additions & 1 deletion plugins/python/pump_subhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ void *uwsgi_request_subhandler_pump(struct wsgi_request *wsgi_req, struct uwsgi_

// call

PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
if (PyTuple_GetItem(wsgi_req->async_args, 0) != wsgi_req->async_environ) {
if (PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ)) {
uwsgi_log_verbose("unable to set environ to the python application callable, consider using the holy env allocator\n");
return NULL;
}
}
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions, wsgi_req);
}

Expand Down
7 changes: 6 additions & 1 deletion plugins/python/web3_subhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ void *uwsgi_request_subhandler_web3(struct wsgi_request *wsgi_req, struct uwsgi_

// call

PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
if (PyTuple_GetItem(wsgi_req->async_args, 0) != wsgi_req->async_environ) {
if (PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ)) {
uwsgi_log_verbose("unable to set environ to the python application callable, consider using the holy env allocator\n");
return NULL;
}
}
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions, wsgi_req);
}

Expand Down
20 changes: 6 additions & 14 deletions plugins/python/wsgi_subhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,13 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_

PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.node", wi->uwsgi_node);

if (PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ)) {
// this is a hack cleaning up bad references when using the cheating allocator
// check https://github.com/unbit/uwsgi/issues/1408
PyObject *tmp_async_args = (PyObject *) wsgi_req->async_args;
if (tmp_async_args->ob_refcnt > 1) {
PyErr_Clear();
Py_DECREF(tmp_async_args);
if (PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ)) {
uwsgi_log_verbose("unable to set environ to the python application callable, consider using the holy env allocator\n");
return NULL;
}
}
}

// call
if (PyTuple_GetItem(wsgi_req->async_args, 0) != wsgi_req->async_environ) {
if (PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ)) {
uwsgi_log_verbose("unable to set environ to the python application callable, consider using the holy env allocator\n");
return NULL;
}
}
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions, wsgi_req);
}

Expand Down

0 comments on commit e61e3e6

Please sign in to comment.