Commit f931938
authored
Merge pull request #2726 from taegyunkim/lazy-atexit
fix: install atexit handlers after apps are initialized
When --lazy or --lazy-apps is set, uwsgi's atexit() handlers, for Python it is uwsgi_python_atexit(), are installed in master process before calling fork(), and when worker loads the application, destructors for static global variables used in Python native extension modules are installed via atexit().
Those static global variables are destructed first and uwsgi atexit() handlers are run.
An application can install Python atexit handler via following two ways
uwsgi Python module's atexit attribute, which will be called by uwsgi_python_atexit() here.
using Python atexit module, which will be called by CPython Py_Finalize(), and uwsgi calls Py_Finalize() also from uwsgi_python_atexit() from here
For both cases, setting --lazy or --lazy-apps changes the order atexit() handlers are installed.
So, if the Python atexit function installed with either of the method calls into native extension module using global states, it results in an undefined behavior leading to segmentation faults.1 file changed
+9
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3202 | 3202 | | |
3203 | 3203 | | |
3204 | 3204 | | |
| 3205 | + | |
| 3206 | + | |
| 3207 | + | |
| 3208 | + | |
3205 | 3209 | | |
3206 | 3210 | | |
3207 | | - | |
3208 | | - | |
3209 | | - | |
3210 | | - | |
3211 | | - | |
3212 | 3211 | | |
3213 | 3212 | | |
3214 | 3213 | | |
| |||
3553 | 3552 | | |
3554 | 3553 | | |
3555 | 3554 | | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
3556 | 3560 | | |
3557 | 3561 | | |
3558 | 3562 | | |
| |||
0 commit comments