You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Python < 3.11 crashes during Py_FinalizeEx (uWSGI worker recycling)
Three root causes of SIGSEGV during interpreter shutdown on Python < 3.11
were identified through uWSGI worker recycling stress tests and fixed:
1. ThreadState allocated via PyObject_Malloc — pymalloc pools can be
disrupted during early Py_FinalizeEx, corrupting the C++ object.
Switched to std::malloc/std::free.
2. deleteme vector used PythonAllocator (PyMem_Malloc) — same pool
corruption issue. Switched to std::allocator (system malloc).
3. _Py_IsFinalizing() is only set AFTER call_py_exitfuncs and
_PyGC_CollectIfEnabled complete, so atexit handlers and __del__
methods could call greenlet.getcurrent() when type objects were
already invalidated, crashing in PyType_IsSubtype. An atexit
handler registered at module init (LIFO = runs first) now sets
a shutdown flag checked by getcurrent(), PyGreenlet_GetCurrent(),
and clear_deleteme_list().
All new code is guarded by #if !GREENLET_PY311 — zero impact on
Python 3.11+. Verified: 0 segfaults in 200 uWSGI worker recycles
on Python 3.9.7 (previously 3-4 crashes in 30 recycles).
Made-with: Cursor
0 commit comments