mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-04 04:31:44 +00:00
fixed a race condition in SIGINT/SIGQUIT
This commit is contained in:
@@ -1695,8 +1695,10 @@ int master_loop(char **argv, char **environ) {
|
||||
uwsgi.workers[uwsgi.mywid].harakiri = 0;
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi.workers[uwsgi.mywid].manage_next_request) {
|
||||
if (WIFEXITED(waitpid_status) && WEXITSTATUS(waitpid_status) == UWSGI_FAILED_APP_CODE) {
|
||||
uwsgi_log("OOPS ! failed loading app in worker %d (pid %d) :( trying again...\n", uwsgi.mywid, (int) diedpid);
|
||||
}
|
||||
else if (uwsgi.workers[uwsgi.mywid].manage_next_request) {
|
||||
uwsgi_log("DAMN ! worker %d (pid: %d) died :( trying respawn ...\n", uwsgi.mywid, (int) diedpid);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ struct uwsgi_fastrouter {
|
||||
int tolerance;
|
||||
int harakiri;
|
||||
|
||||
struct fastrouter_session *fr_table[2048];
|
||||
struct fastrouter_session **fr_table;
|
||||
|
||||
int fr_subserver;
|
||||
int fr_stats_server;
|
||||
@@ -358,8 +358,9 @@ void fastrouter_loop(int id) {
|
||||
ufr.fr_subserver = -1;
|
||||
ufr.fr_stats_server = -1;
|
||||
|
||||
ufr.fr_table = uwsgi_malloc(sizeof(struct fastrouter_session) * uwsgi.max_fd);
|
||||
|
||||
for(i=0;i<2048;i++) {
|
||||
for(i=0;i<(int)uwsgi.max_fd;i++) {
|
||||
ufr.fr_table[i] = NULL;
|
||||
}
|
||||
|
||||
@@ -525,7 +526,9 @@ void fastrouter_thread(void *arg) {
|
||||
uwsgi.shared->gateways_harakiri[*id] = 0;
|
||||
}
|
||||
|
||||
//FASTROUTER_LOCK
|
||||
nevents = event_queue_wait_multi(ufr.queue, delta, events, ufr.nevents);
|
||||
//FASTROUTER_UNLOCK
|
||||
|
||||
if (uwsgi.master_process && ufr.harakiri > 0) {
|
||||
uwsgi.shared->gateways_harakiri[*id] = time(NULL) + ufr.harakiri;
|
||||
|
||||
+12
-12
@@ -539,7 +539,7 @@ PyObject *uwsgi_mount_loader(void *arg1) {
|
||||
|
||||
if ( !strcmp(what+strlen(what)-3, ".py") || !strcmp(what+strlen(what)-5, ".wsgi")) {
|
||||
callable = uwsgi_file_loader((void *)what);
|
||||
if (!callable) exit(1);
|
||||
if (!callable) exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
else if (!strcmp(what+strlen(what)-4, ".ini")) {
|
||||
callable = uwsgi_paste_loader((void *)what);
|
||||
@@ -658,36 +658,36 @@ PyObject *uwsgi_paste_loader(void *arg1) {
|
||||
paste_module = PyImport_ImportModule("paste.deploy");
|
||||
if (!paste_module) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
paste_dict = PyModule_GetDict(paste_module);
|
||||
if (!paste_dict) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
paste_loadapp = PyDict_GetItemString(paste_dict, "loadapp");
|
||||
if (!paste_loadapp) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
paste_arg = PyTuple_New(1);
|
||||
if (!paste_arg) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
if (PyTuple_SetItem(paste_arg, 0, PyString_FromString(paste))) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
paste_app = PyEval_CallObject(paste_loadapp, paste_arg);
|
||||
if (!paste_app) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
|
||||
@@ -709,7 +709,7 @@ PyObject *uwsgi_eval_loader(void *arg1) {
|
||||
if (!wsgi_eval_node) {
|
||||
PyErr_Print();
|
||||
uwsgi_log( "failed to parse <eval> code\n");
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
wsgi_compiled_node = (PyObject *) PyNode_Compile(wsgi_eval_node, "uwsgi_eval_config");
|
||||
@@ -717,14 +717,14 @@ PyObject *uwsgi_eval_loader(void *arg1) {
|
||||
if (!wsgi_compiled_node) {
|
||||
PyErr_Print();
|
||||
uwsgi_log( "failed to compile eval code\n");
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
|
||||
wsgi_eval_module = PyImport_ExecCodeModule("uwsgi_eval_config", wsgi_compiled_node);
|
||||
if (!wsgi_eval_module) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
|
||||
@@ -733,7 +733,7 @@ PyObject *uwsgi_eval_loader(void *arg1) {
|
||||
up.loader_dict = PyModule_GetDict(wsgi_eval_module);
|
||||
if (!up.loader_dict) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
|
||||
|
||||
@@ -748,7 +748,7 @@ PyObject *uwsgi_eval_loader(void *arg1) {
|
||||
if (wsgi_eval_callable) {
|
||||
if (!PyFunction_Check(wsgi_eval_callable) && !PyCallable_Check(wsgi_eval_callable)) {
|
||||
uwsgi_log( "you must define a callable object in your code\n");
|
||||
exit(1);
|
||||
exit(UWSGI_FAILED_APP_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +194,12 @@ void uwsgi_python_atexit() {
|
||||
|
||||
// this time we use this higher level function
|
||||
// as this code can be executed in a signal handler
|
||||
PyGILState_Ensure();
|
||||
if (!Py_IsInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (uwsgi.has_threads)
|
||||
PyGILState_Ensure();
|
||||
// no need to worry about freeing memory
|
||||
PyObject *uwsgi_dict = get_uwsgi_pydict("uwsgi");
|
||||
if (uwsgi_dict) {
|
||||
|
||||
@@ -231,6 +231,7 @@ static struct option long_base_options[] = {
|
||||
#ifdef UWSGI_ASYNC
|
||||
{"async", required_argument, 0, LONG_ARGS_ASYNC},
|
||||
#endif
|
||||
{"max-fd", required_argument, 0, LONG_ARGS_MAX_FD},
|
||||
{"logto", required_argument, 0, LONG_ARGS_LOGTO},
|
||||
{"logto2", required_argument, 0, LONG_ARGS_LOGTO2},
|
||||
{"logfile-chown", no_argument, &uwsgi.logfile_chown, 1},
|
||||
@@ -636,6 +637,8 @@ static void uwsgi_signal_spoolers(int signum) {
|
||||
|
||||
void kill_them_all(int signum) {
|
||||
int i;
|
||||
|
||||
if (uwsgi.to_hell == 1) return;
|
||||
uwsgi.to_hell = 1;
|
||||
|
||||
if (uwsgi.reload_mercy > 0) {
|
||||
@@ -1932,9 +1935,18 @@ int uwsgi_start(void *v_argv) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (uwsgi.requested_max_fd) {
|
||||
uwsgi.rl.rlim_cur = uwsgi.requested_max_fd;
|
||||
uwsgi.rl.rlim_max = uwsgi.requested_max_fd;
|
||||
if (setrlimit(RLIMIT_NOFILE, &uwsgi.rl)) {
|
||||
uwsgi_error("setrlimit()");
|
||||
}
|
||||
}
|
||||
|
||||
if (!getrlimit(RLIMIT_NOFILE, &uwsgi.rl)) {
|
||||
uwsgi.max_fd = uwsgi.rl.rlim_cur;
|
||||
uwsgi_log("detected max file descriptor number: %d\n", (int) uwsgi.max_fd);
|
||||
}
|
||||
|
||||
uwsgi.wsgi_requests = uwsgi_malloc(sizeof(struct wsgi_request *) * uwsgi.cores);
|
||||
@@ -3257,6 +3269,9 @@ static int manage_base_opt(int i, char *optarg) {
|
||||
case LONG_ARGS_LOGTO:
|
||||
logto(optarg);
|
||||
return 1;
|
||||
case LONG_ARGS_MAX_FD:
|
||||
uwsgi.requested_max_fd = atoi(optarg);
|
||||
return 1;
|
||||
case LONG_ARGS_LOGTO2:
|
||||
uwsgi.logto2 = optarg;
|
||||
return 1;
|
||||
|
||||
@@ -563,6 +563,7 @@ struct uwsgi_opt {
|
||||
#define LONG_ARGS_EXEC_PRE_JAIL 17175
|
||||
#define LONG_ARGS_EXEC_POST_JAIL 17176
|
||||
#define LONG_ARGS_EXEC_IN_JAIL 17177
|
||||
#define LONG_ARGS_MAX_FD 17178
|
||||
|
||||
|
||||
#define UWSGI_OK 0
|
||||
@@ -624,6 +625,7 @@ struct uwsgi_opt {
|
||||
#define UWSGI_RELOAD_CODE 17
|
||||
#define UWSGI_END_CODE 30
|
||||
#define UWSGI_EXILE_CODE 26
|
||||
#define UWSGI_FAILED_APP_CODE 22
|
||||
|
||||
#define MAX_VARS 64
|
||||
#define MAX_LOOPS 60
|
||||
@@ -1399,6 +1401,7 @@ struct uwsgi_server {
|
||||
int mules_cnt;
|
||||
int farms_cnt;
|
||||
|
||||
rlim_t requested_max_fd;
|
||||
rlim_t max_fd;
|
||||
|
||||
struct timeval start_tv;
|
||||
|
||||
Reference in New Issue
Block a user