|
@@ -20,6 +20,7 @@
|
20
|
20
|
#include "pyworker.h"
|
21
|
21
|
|
22
|
22
|
|
|
23
|
+static short _wtimeout;
|
23
|
24
|
/**@brief 1 if worker idle else 0 */
|
24
|
25
|
static short _worker_idle;
|
25
|
26
|
/**@brief Indicate that a worker is idle */
|
|
@@ -83,6 +84,7 @@ int work333(int wrk_id)
|
83
|
84
|
worker_set_busy();
|
84
|
85
|
count++;
|
85
|
86
|
environ = update_pyenv(py_osmod, envp);
|
|
87
|
+ _wtimeout = 0;
|
86
|
88
|
|
87
|
89
|
libpyfcgi_clean_response();
|
88
|
90
|
libpyfcgi.out = out_stream;
|
|
@@ -94,7 +96,19 @@ int work333(int wrk_id)
|
94
|
96
|
{
|
95
|
97
|
Py_INCREF(entry_ret);
|
96
|
98
|
}
|
97
|
|
-
|
|
99
|
+
|
|
100
|
+ if(_wtimeout)
|
|
101
|
+ {
|
|
102
|
+ PyObject *type, *exc, *tb, *tmp;
|
|
103
|
+ // Changing exception to a TimeoutError, but keeping
|
|
104
|
+ // the traceback to display
|
|
105
|
+ PyErr_Fetch(&type, &exc, &tb);
|
|
106
|
+ PyErr_SetString(PyExc_TimeoutError, "Request timeout");
|
|
107
|
+ PyErr_Fetch(&type, &exc, &tmp);
|
|
108
|
+ PyErr_Restore(type, exc, tb);
|
|
109
|
+ log_expt(LOG_ERR);
|
|
110
|
+ libpyfcgi_timeout(); // Sending headers if possible
|
|
111
|
+ }
|
98
|
112
|
if(PyErr_Occurred())
|
99
|
113
|
{
|
100
|
114
|
pyfcgi_log(LOG_ERR, "PEP333 entrypoint function triggered an exception");
|
|
@@ -132,6 +146,10 @@ int work333(int wrk_id)
|
132
|
146
|
stop.tv_sec -= 1;
|
133
|
147
|
}
|
134
|
148
|
pyfcgi_wd_pause();
|
|
149
|
+ if(_wtimeout)
|
|
150
|
+ {
|
|
151
|
+ exit(PYFCGI_TIMEOUT);
|
|
152
|
+ }
|
135
|
153
|
pyfcgi_log(LOG_DEBUG, "Worker[%d] request %d END [OK] %lu bytes in %ld.%06lds",
|
136
|
154
|
wrk_id, count, libpyfcgi.rep_sz, stop.tv_sec, stop.tv_usec);
|
137
|
155
|
|
|
@@ -625,7 +643,12 @@ void worker_sighandler(int signum)
|
625
|
643
|
|
626
|
644
|
void worker_sigalrmhandler(int signum)
|
627
|
645
|
{
|
628
|
|
- //pyfcgi_log(LOG_WARNING, "Timeout, exiting...");
|
|
646
|
+ _wtimeout = 1;
|
|
647
|
+ if(!_worker_idle)
|
|
648
|
+ {
|
|
649
|
+ // Call PyErr_Interrupt() in order to stop python
|
|
650
|
+ PyErr_SetInterrupt();
|
|
651
|
+ }
|
629
|
652
|
worker_set_busy();
|
630
|
|
- exit(PYFCGI_TIMEOUT);
|
|
653
|
+ return;
|
631
|
654
|
}
|