New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash when using sqlite3 with subinterpreters #92036
Comments
|
In the main branch, the _sqlite3 extension was converted to the multi-phase initialization API (PEP 489) which made the extension safer to use with subinterpreters. |
|
See also #90228 which is similar but has been fixed. |
|
In the 3.10 branch, the script doesn't crash before my change: |
|
I can reproduce this on my Mac on 3.9 and 3.10. |
|
It seems like the problem comes from the Traceback when the bug occurs: |
When Py_EndInterpreter() is called to finalize a subinterpreter, objects still tracked by the GC are untracked. Later, if one of these object is deleted and its deallocator function expect the object to be tracked by the GC, the deallocator function can crash. Leak one strong reference on purpose so the object is never deleted and its deallocator is not called.
Fix a crash in subinterpreters related to the garbage collector. When a subinterpreter is deleted, untrack all objects tracked by its GC. To prevent a crash in deallocator functions expecting objects to be tracked by the GC, leak a strong reference to these objects on purpose, so they are never deleted and their deallocator functions are not called.
Well, gc_fini_untrack() solves one problem but not all of them :-( I wrote PR #92037 to fix this issue. Explanation of this bug:
In this order, everything is fine: the interpreter A still exists when the interpreter B overrides the The problem is when the interpreter A is deleted before the interpreter B registers is its own adapter (override the key in the shared dict). In this case, the function is untracked by the GC. Problem: deleting a function requires the function to be tracked by the GC. Othserwise, _PyObject_GC_UNTRACK() assertion fails: this function must only be called on objects called by the GC. |
|
By the way, when the bug occurs, Python built in debug mode displays this error: But then hangs: _PyObject_Dump() tries to acquire the GIL, but another interpreter is holding it... |
Running sqlite3_crash.py on Python 3.9 and 3.10 fail randomly with an assertion failure in _PyObject_GC_UNTRACK() called by func_dealloc().
The problem is that a function is allocated in an interpreter and deallocated in another interpreter.
I built Python 3.10 with pyobject_ob_interp.patch. When the bug occurs, I get:
0x7fffa40010300x7fffc0001030The text was updated successfully, but these errors were encountered: