-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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:
|
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... |
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.
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. (cherry picked from commit 1424336) Co-authored-by: Victor Stinner <[email protected]>
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. (cherry picked from commit 1424336) Co-authored-by: Victor Stinner <[email protected]>
I got the confirmation that my change fix Kodi crash: #90619 (comment) |
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. (cherry picked from commit 1424336) Co-authored-by: Victor Stinner <[email protected]>
I marked #90619 "Kodi crashing" as a duplicate of this bug. |
@vstinner Do you know what versions of 3.9 and 3.10 will include this fix? Oh. Looks like 3.10.5 in a month |
The next releases. See: |
If you are blocked, you might try to detect which deleted objects are causing crashes and keep a copy of them in a list somewhere: #92036 (comment) Or even somehow call Py_IncRef() on them. |
release: - https://www.python.org/downloads/release/python-3913/ changelog: - https://docs.python.org/release/3.9.13/whatsnew/changelog.html upstream fix for dropped patch - python/cpython#80254 - python/cpython#11984 - python/cpython#90228 - python/cpython#92036 - python/cpython#92037 - python/cpython#92297 - bpo-36073 - was - python/cpython#30579 - python/cpython#30580
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. (cherry picked from commit 1424336) Co-authored-by: Victor Stinner <[email protected]>
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:
0x7fffa4001030
0x7fffc0001030
The text was updated successfully, but these errors were encountered: