Преглед на файлове

Bugfix in PEP333 worker when application trigger an exception

Yann Weber преди 5 години
родител
ревизия
cc0af1abb2
променени са 2 файла, в които са добавени 13 реда и са изтрити 9 реда
  1. 1
    4
      src/pyutils.c
  2. 12
    5
      src/pyworker.c

+ 1
- 4
src/pyutils.c Целия файл

@@ -11,15 +11,12 @@ void pyinit()
11 11
 		swprintf(PyFCGI_conf.context.venv_path, PATH_MAX, L"%s",
12 12
 			venv_path);
13 13
 		Py_SetPythonHome(PyFCGI_conf.context.venv_path);
14
-		pyfcgi_log(LOG_INFO, "Virtualenv found : setting PYTHONHOME : '%s'",
14
+		pyfcgi_log(LOG_INFO, "Virtualenv found : '%s'",
15 15
 			venv_path);
16 16
 
17 17
 		swprintf(PyFCGI_conf.context.python_path, PATH_MAX,
18 18
 			L"%s/bin/python3", venv_path);
19 19
 		Py_SetProgramName(PyFCGI_conf.context.python_path);
20
-
21
-		pyfcgi_log(LOG_INFO, "Setting programm name : '%ls'",
22
-			PyFCGI_conf.context.python_path);
23 20
 	}
24 21
 
25 22
 	Py_Initialize();

+ 12
- 5
src/pyworker.c Целия файл

@@ -92,24 +92,31 @@ int work333(int wrk_id, int semid)
92 92
 		libpyfcgi.out = out_stream;
93 93
 		args = Py_BuildValue("OO", environ, start_response);
94 94
 		entry_ret = PyObject_CallObject(entry_fun, args);
95
-		Py_INCREF(entry_ret);
95
+		if(entry_ret && entry_ret != Py_None )
96
+		{
97
+			Py_INCREF(entry_ret);
98
+		}
96 99
 
97 100
 		if(PyErr_Occurred())
98 101
 		{
102
+			pyfcgi_log(LOG_ERR, "PEP333 entrypoint function triggered an exception");
99 103
 			log_expt(LOG_ERR);
100 104
 		}
101 105
 		// able to process returned value
102 106
 		// Simulate python call of libpyfcgi.write_body()
103
-		_pyfcgi_write_body(entry_ret);
104
-		if(PyErr_Occurred())
107
+		if(entry_ret && entry_ret != Py_None)
105 108
 		{
106
-			log_expt(LOG_ERR);
109
+			_pyfcgi_write_body(entry_ret);
110
+			if(PyErr_Occurred())
111
+			{
112
+				log_expt(LOG_ERR);
113
+			}
114
+			Py_DECREF(entry_ret);
107 115
 		}
108 116
 
109 117
 		// clean stuffs
110 118
 		Py_DECREF(args);
111 119
 		Py_DECREF(environ);
112
-		Py_DECREF(entry_ret);
113 120
 		// flush & logs pystdout & pystderr
114 121
 		PyObject_CallObject(pyflush[0], NULL);
115 122
 		PyObject_CallObject(pyflush[1], NULL);

Loading…
Отказ
Запис