From 86e651f5e7e686042684e22ae0536720808ffbfa Mon Sep 17 00:00:00 2001 From: Unbit Date: Thu, 25 Apr 2013 07:09:39 +0200 Subject: [PATCH] call gevent atexit hook before destroying uwsgi-related greenlets --- core/utils.c | 2 ++ plugins/gevent/gevent.c | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/utils.c b/core/utils.c index 08bc4d9b..167d33a1 100644 --- a/core/utils.c +++ b/core/utils.c @@ -588,6 +588,8 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) { } } else { + // could have been changed in the mean time + ub = wsgi_req->response_buffer; wsgi_req->write_errors++; } uwsgi_buffer_destroy(ub); diff --git a/plugins/gevent/gevent.c b/plugins/gevent/gevent.c index 31d6c353..b11149a3 100644 --- a/plugins/gevent/gevent.c +++ b/plugins/gevent/gevent.c @@ -29,6 +29,16 @@ PyObject *py_uwsgi_gevent_graceful(PyObject *self, PyObject *args) { uwsgi_log("Gracefully killing worker %d (pid: %d)...\n", uwsgi.mywid, uwsgi.mypid); uwsgi.workers[uwsgi.mywid].manage_next_request = 0; + + // no need to worry about freeing memory + PyObject *uwsgi_dict = get_uwsgi_pydict("uwsgi"); + if (uwsgi_dict) { + PyObject *ae = PyDict_GetItemString(uwsgi_dict, "atexit"); + if (ae) { + python_call(ae, PyTuple_New(0), 0, NULL); + } + } + uwsgi_log_verbose("stopping gevent signals watchers for worker %d (pid: %d)...\n", uwsgi.mywid, uwsgi.mypid); PyObject_CallMethod(ugevent.my_signal_watcher, "stop", NULL); @@ -430,15 +440,6 @@ static void gevent_loop() { } if (uwsgi.workers[uwsgi.mywid].manage_next_request == 0) { - // no need to worry about freeing memory - PyObject *uwsgi_dict = get_uwsgi_pydict("uwsgi"); - if (uwsgi_dict) { - PyObject *ae = PyDict_GetItemString(uwsgi_dict, "atexit"); - if (ae) { - python_call(ae, PyTuple_New(0), 0, NULL); - } - } - uwsgi_log("goodbye to the gevent Hub on worker %d (pid: %d)\n", uwsgi.mywid, uwsgi.mypid); if (ugevent.destroy) { exit(0);