diff --git a/core/async.c b/core/async.c index 41651fdf..dc87ae22 100644 --- a/core/async.c +++ b/core/async.c @@ -481,7 +481,12 @@ void async_loop() { // signals are executed in the main stack... in the future we could have dedicated stacks for them if (uwsgi.signal_socket > -1 && (interesting_fd == uwsgi.signal_socket || interesting_fd == uwsgi.my_signal_socket)) { - uwsgi_receive_signal(interesting_fd, "worker", uwsgi.mywid); + uwsgi.wsgi_req = find_first_available_wsgi_req(); + if (uwsgi.wsgi_req == NULL) { + uwsgi_async_queue_is_full((time_t)now); + continue; + } + uwsgi_receive_signal(uwsgi.wsgi_req, interesting_fd, "worker", uwsgi.mywid); continue; } diff --git a/core/master_checks.c b/core/master_checks.c index ebf63f8a..2d6bab4b 100644 --- a/core/master_checks.c +++ b/core/master_checks.c @@ -160,12 +160,6 @@ int uwsgi_master_check_workers_deadline() { int i,j; int ret = 0; for (i = 1; i <= uwsgi.numproc; i++) { - if (uwsgi.workers[i].harakiri_total > 0) { - if (uwsgi.workers[i].harakiri_total < (time_t) uwsgi.current_time) { - trigger_harakiri(i); - ret = 1; - } - } for(j=0;j 0) { diff --git a/core/mule.c b/core/mule.c index 8a2211c7..a40a1777 100644 --- a/core/mule.c +++ b/core/mule.c @@ -198,7 +198,7 @@ void uwsgi_mule_handler() { #ifdef UWSGI_DEBUG uwsgi_log_verbose("master sent signal %d to mule %d\n", uwsgi_signal, uwsgi.muleid); #endif - if (uwsgi_signal_handler(uwsgi_signal)) { + if (uwsgi_signal_handler(NULL, uwsgi_signal)) { uwsgi_log_verbose("error managing signal %d on mule %d\n", uwsgi_signal, uwsgi.muleid); } } @@ -362,7 +362,7 @@ retry: #ifdef UWSGI_DEBUG uwsgi_log_verbose("master sent signal %d to mule %d\n", uwsgi_signal, uwsgi.muleid); #endif - if (uwsgi_signal_handler(uwsgi_signal)) { + if (uwsgi_signal_handler(NULL, uwsgi_signal)) { uwsgi_log_verbose("error managing signal %d on mule %d\n", uwsgi_signal, uwsgi.muleid); } // set the error condition diff --git a/core/signal.c b/core/signal.c index f93cd9eb..f496d761 100644 --- a/core/signal.c +++ b/core/signal.c @@ -2,7 +2,7 @@ extern struct uwsgi_server uwsgi; -int uwsgi_signal_handler(uint8_t sig) { +int uwsgi_signal_handler(struct wsgi_request *wsgi_req, uint8_t sig) { struct uwsgi_signal_entry *use = NULL; @@ -41,12 +41,12 @@ int uwsgi_signal_handler(uint8_t sig) { // set harakiri here (if required and if i am a worker) - if (uwsgi.mywid > 0) { + if (uwsgi.mywid > 0 && wsgi_req) { uwsgi.workers[uwsgi.mywid].sig = 1; uwsgi.workers[uwsgi.mywid].signum = sig; uwsgi.workers[uwsgi.mywid].signals++; if (uwsgi.harakiri_options.workers > 0) { - set_harakiri(NULL, uwsgi.harakiri_options.workers); + set_harakiri(wsgi_req, uwsgi.harakiri_options.workers); } } else if (uwsgi.muleid > 0) { @@ -65,10 +65,10 @@ int uwsgi_signal_handler(uint8_t sig) { int ret = uwsgi.p[use->modifier1]->signal_handler(sig, use->handler); - if (uwsgi.mywid > 0) { + if (uwsgi.mywid > 0 && wsgi_req) { uwsgi.workers[uwsgi.mywid].sig = 0; - if (uwsgi.workers[uwsgi.mywid].harakiri_total > 0) { - set_harakiri(NULL, 0); + if (uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].harakiri > 0) { + set_harakiri(wsgi_req, 0); } } else if (uwsgi.muleid > 0) { @@ -405,7 +405,7 @@ void uwsgi_route_signal(uint8_t sig) { } -int uwsgi_signal_wait(int signum) { +int uwsgi_signal_wait(struct wsgi_request *wsgi_req, int signum) { int wait_for_specific_signal = 0; uint8_t uwsgi_signal = 0; @@ -430,7 +430,7 @@ cycle: uwsgi_error("read()"); } else { - (void) uwsgi_signal_handler(uwsgi_signal); + (void) uwsgi_signal_handler(wsgi_req, uwsgi_signal); if (wait_for_specific_signal) { if (signum != uwsgi_signal) goto cycle; @@ -443,7 +443,7 @@ cycle: uwsgi_error("read()"); } else { - (void) uwsgi_signal_handler(uwsgi_signal); + (void) uwsgi_signal_handler(wsgi_req, uwsgi_signal); if (wait_for_specific_signal) { if (signum != uwsgi_signal) goto cycle; @@ -457,7 +457,7 @@ cycle: return received_signal; } -void uwsgi_receive_signal(int fd, char *name, int id) { +void uwsgi_receive_signal(struct wsgi_request *wsgi_req, int fd, char *name, int id) { uint8_t uwsgi_signal; @@ -474,7 +474,7 @@ void uwsgi_receive_signal(int fd, char *name, int id) { #ifdef UWSGI_DEBUG uwsgi_log_verbose("master sent signal %d to %s %d\n", uwsgi_signal, name, id); #endif - if (uwsgi_signal_handler(uwsgi_signal)) { + if (uwsgi_signal_handler(wsgi_req, uwsgi_signal)) { uwsgi_log_verbose("error managing signal %d on %s %d\n", uwsgi_signal, name, id); } } diff --git a/core/spooler.c b/core/spooler.c index cc92c701..92bef674 100644 --- a/core/spooler.c +++ b/core/spooler.c @@ -458,7 +458,7 @@ void spooler(struct uwsgi_spooler *uspool) { if (event_queue_wait(spooler_event_queue, timeout, &interesting_fd) > 0) { if (uwsgi.master_process) { if (interesting_fd == uwsgi.shared->spooler_signal_pipe[1]) { - uwsgi_receive_signal(interesting_fd, "spooler", (int) getpid()); + uwsgi_receive_signal(NULL, interesting_fd, "spooler", (int) getpid()); } } } diff --git a/core/utils.c b/core/utils.c index 25ef4e3c..32728990 100644 --- a/core/utils.c +++ b/core/utils.c @@ -53,21 +53,12 @@ void inc_harakiri(struct wsgi_request *wsgi_req, int sec) { // set worker harakiri void set_harakiri(struct wsgi_request *wsgi_req, int sec) { - if (!wsgi_req) { - if (sec == 0) { - uwsgi.workers[uwsgi.mywid].harakiri_total = 0; - } - else { - uwsgi.workers[uwsgi.mywid].harakiri_total = uwsgi_now() + sec; - } + if (!wsgi_req) return; + if (sec == 0) { + uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].harakiri = 0; } else { - if (sec == 0) { - uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].harakiri = 0; - } - else { - uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].harakiri = uwsgi_now() + sec; - } + uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].harakiri = uwsgi_now() + sec; } if (!uwsgi.master_process) { alarm(sec); @@ -1525,7 +1516,7 @@ int wsgi_req_accept(int queue, struct wsgi_request *wsgi_req) { thunder_unlock; - uwsgi_receive_signal(interesting_fd, "worker", uwsgi.mywid); + uwsgi_receive_signal(wsgi_req, interesting_fd, "worker", uwsgi.mywid); if (uwsgi.threads > 1) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ret); diff --git a/plugins/coroae/coroae.c b/plugins/coroae/coroae.c index 369c2f4d..2113a743 100644 --- a/plugins/coroae/coroae.c +++ b/plugins/coroae/coroae.c @@ -187,7 +187,7 @@ end: XS(XS_coroae_sighandler) { int sigfd = (long) XSANY.any_ptr; - uwsgi_receive_signal(sigfd, "worker", uwsgi.mywid); + uwsgi_receive_signal(NULL, sigfd, "worker", uwsgi.mywid); } XS(XS_coroae_acceptor) { diff --git a/plugins/gccgo/gccgo_plugin.c b/plugins/gccgo/gccgo_plugin.c index 43bf7798..d67eefd1 100644 --- a/plugins/gccgo/gccgo_plugin.c +++ b/plugins/gccgo/gccgo_plugin.c @@ -342,7 +342,7 @@ static void uwsgi_gccgo_signal_goroutine(void *arg) { for(;;) { runtime_pollWait(pdesc, 'r'); retry: - uwsgi_receive_signal(*fd, "worker", uwsgi.mywid); + uwsgi_receive_signal(NULL, *fd, "worker", uwsgi.mywid); if (uwsgi_is_again()) continue; goto retry; } diff --git a/plugins/gevent/gevent.c b/plugins/gevent/gevent.c index 6c57545c..099bfc91 100644 --- a/plugins/gevent/gevent.c +++ b/plugins/gevent/gevent.c @@ -140,7 +140,7 @@ PyObject *py_uwsgi_gevent_signal_handler(PyObject * self, PyObject * args) { return NULL; } - uwsgi_receive_signal(signal_socket, "worker", uwsgi.mywid); + uwsgi_receive_signal(NULL, signal_socket, "worker", uwsgi.mywid); Py_INCREF(Py_None); return Py_None; diff --git a/plugins/psgi/uwsgi_plmodule.c b/plugins/psgi/uwsgi_plmodule.c index e062f939..a289e07b 100644 --- a/plugins/psgi/uwsgi_plmodule.c +++ b/plugins/psgi/uwsgi_plmodule.c @@ -432,10 +432,10 @@ XS(XS_signal_wait) { wsgi_req->signal_received = -1; if (items > 0) { - received_signal = uwsgi_signal_wait(SvIV(ST(0))); + received_signal = uwsgi_signal_wait(wsgi_req, SvIV(ST(0))); } else { - received_signal = uwsgi_signal_wait(-1); + received_signal = uwsgi_signal_wait(wsgi_req, -1); } if (received_signal < 0) { diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index fe29bb13..30471728 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -46,10 +46,10 @@ static PyObject *py_uwsgi_signal_wait(PyObject * self, PyObject * args) { UWSGI_RELEASE_GIL; if (wait_for_specific_signal) { - received_signal = uwsgi_signal_wait(uwsgi_signal); + received_signal = uwsgi_signal_wait(wsgi_req, uwsgi_signal); } else { - received_signal = uwsgi_signal_wait(-1); + received_signal = uwsgi_signal_wait(wsgi_req, -1); } if (received_signal < 0) { diff --git a/plugins/rack/rack_api.c b/plugins/rack/rack_api.c index 8567339e..2e039167 100644 --- a/plugins/rack/rack_api.c +++ b/plugins/rack/rack_api.c @@ -766,10 +766,10 @@ static VALUE uwsgi_ruby_signal_wait(int argc, VALUE *argv, VALUE *class) { } if (wait_for_specific_signal) { - received_signal = uwsgi_signal_wait(uwsgi_signal); + received_signal = uwsgi_signal_wait(wsgi_req, uwsgi_signal); } else { - received_signal = uwsgi_signal_wait(-1); + received_signal = uwsgi_signal_wait(wsgi_req, -1); } if (received_signal < 0) { diff --git a/uwsgi.h b/uwsgi.h index f8966b11..d3c35cac 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2908,7 +2908,8 @@ struct uwsgi_worker { uint64_t failed_requests; // renamed in 2.1 (was 'harakiri') - time_t harakiri_total; + time_t harakiri_unused; + // renamed in 2.1 (was 'user_harakiri') time_t user_harakiri_unused; uint64_t harakiri_count; int pending_harakiri; @@ -3238,7 +3239,7 @@ int uwsgi_register_signal(uint8_t, char *, void *, uint8_t); int uwsgi_add_file_monitor(uint8_t, char *); int uwsgi_add_timer(uint8_t, int); int uwsgi_signal_add_rb_timer(uint8_t, int, int); -int uwsgi_signal_handler(uint8_t); +int uwsgi_signal_handler(struct wsgi_request *, uint8_t); void uwsgi_route_signal(uint8_t); @@ -3632,7 +3633,7 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo ssize_t uwsgi_mule_get_msg(int, int, char *, size_t, int); -int uwsgi_signal_wait(int); +int uwsgi_signal_wait(struct wsgi_request *, int); struct uwsgi_app *uwsgi_add_app(int, uint8_t, char *, int, void *, void *); int uwsgi_signal_send(int, uint8_t); int uwsgi_remote_signal_send(char *, uint8_t); @@ -3892,7 +3893,7 @@ int uwsgi_is_file2(char *, struct stat *); int uwsgi_is_dir(char *); int uwsgi_is_link(char *); -void uwsgi_receive_signal(int, char *, int); +void uwsgi_receive_signal(struct wsgi_request *, int, char *, int); void uwsgi_exec_atexit(void); struct uwsgi_stats {