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
{{ message }}
Repository navigation
_socket extension C capsule cannot be visited by the GC and so _socket.socket type may stay alive longer than expected #108240
The GC cannot visit the strong reference to the type stored in _socket.CAPI capsule (C API). In Python, creating a heap type creates a reference cycle. For example, a type MRO contains the type. Methods also contain a strong reference to their type.
FYI, it seems that work on isolating the _curses extension module is suspended. #101714 (comment)
So, should we re-open @chgnrdv PR about isolating _curses? Seems work almost done, but isolating module only for avoid reference leak looks kinda weird.
Activity
pythongh-108240: Fix a reference cycle in _socket.CAPI capsule
vstinner commentedon Aug 21, 2023
I wrote PR #108241 to fix the issue for the _socket extension: avoid strong references in the capsule object.
vstinner commentedon Aug 21, 2023
_cursesextension is affected by the same bug:_curses._C_APIcapsule stores a strong reference to_curses.windowheap type.Extensions not affected by the issue, using borrowed references:
_datetime.datetime_CAPIstores borrowed references to_datetimeheap typespyexpat.expat_CAPIdoes not store typesunicodedata._ucnhash_CAPIdoes not store types_testcapicapsules don't store typesvstinner commentedon Aug 21, 2023
By the way, commit 46366ca may have introduced a leak: see PR #107577.
vstinner commentedon Aug 21, 2023
I closed issue #107789 as a duplicate of this issue.
vstinner commentedon Aug 21, 2023
Oh, @Eclips4 found that the
_decimalextension is also affected: #107577 (comment)Eclips4 commentedon Aug 21, 2023
Probably related: #107994
vstinner commentedon Aug 21, 2023
Oh right, the
_decimalextension has no capsule, so the refleak is unrelated to this issue.vstinner commentedon Aug 21, 2023
cc @erlend-aasland @corona10 @pablogsal: yet another complex GC issue involving extension multi-phase initialization and the garbage collector.
vstinner commentedon Aug 21, 2023
The
_cursesextension was not ported to multi-phase init API (PEP 489) yet. It still uses static types.Eclips4 commentedon Aug 21, 2023
You mean leak in the
_cursesis a known issue?vstinner commentedon Aug 21, 2023
Yes. It should be ported to multi-phase init and its static types should be converted to heap types.
CharlieZhao95 commentedon Aug 22, 2023
FYI, it seems that work on isolating the
_cursesextension module is suspended. #101714 (comment)Eclips4 commentedon Aug 22, 2023
So, should we re-open @chgnrdv PR about isolating
_curses? Seems work almost done, but isolating module only for avoid reference leak looks kinda weird.4 remaining items
erlend-aasland commentedon Aug 22, 2023
Yes, storing the state in the interpreter is an option, but I don't think we want to do that for tkinter, readline, and curses.
pythongh-108240: Add PyCapsule_SetTraverse() function
pythongh-108240: Add PyCapsule_SetTraverse() function
pythongh-108240: Add PyCapsule_SetTraverse() function
pythongh-108240: Add PyCapsule_SetTraverse() function
pythongh-108240: Add _PyCapsule_SetTraverse() function
pythongh-108240: Add _PyCapsule_SetTraverse() interal function
gh-108240: Add _PyCapsule_SetTraverse() internal function (#108339)
vstinner commentedon Aug 23, 2023
Fixed by commit 513c89d
Thanks for your bug report @Eclips4.
pythongh-108240: _PyCapsule_SetTraverse() rejects NULL callbacks
pythongh-108240: _PyCapsule_SetTraverse() rejects NULL callbacks
gh-108240: _PyCapsule_SetTraverse() rejects NULL callbacks (#108417)
pythongh-108240: Add pycore_capsule.h internal header file
gh-108240: Add pycore_capsule.h internal header file (#108596)