-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-115874: Don't use module state in teedataobject tp_dealloc #116204
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
gh-115874: Don't use module state in teedataobject tp_dealloc #116204
Conversation
We could also add your repro as a regression test, @brandtbucher. |
I think adding the test is a good idea. Maybe use one of the helpers that launches a new subprocess? Honestly, I’m not sure why the safe dealloc function needs a type at all. It’s not possible to have any other type here, right? In fact, it’s basically just reinventing the existing trashcan mechanism. Either one of two things is true: the type of a linked object can never be anything other than |
Well, it's not a basetype, so there is no risk of subtypes here. After a second (quick) look, I see no reason to use the module state here at all. I'll be able to have a closer look in a couple of hours. Feel free to continue working on this PR in the mean time if you want, Brandt. We could just decref the linked list in the dealloc function; the |
FTR, here's the issue and commit that added the safe-decref helper: |
Using the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not obvious why the typing module is needed for tests. It may make the test unreliable. Otherwise LGTM.
It is not obvious for me either. @brandtbucher, could you add an explanatory comment? |
Away from my laptop for the weekend, but I’ll look when I get back. Honestly, I think it may just have to do with the order in which cycles are created (and the order in which they, and the items within them, are cleared). |
Perhaps the GitHub reference is enough for now. |
@@ -1699,6 +1699,14 @@ def test_tee(self): | |||
self.pickletest(proto, a, compare=ans) | |||
self.pickletest(proto, b, compare=ans) | |||
|
|||
def test_tee_dealloc_segfault(self): | |||
# gh-115874: segfaults when accessing module state in tp_dealloc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brandtbucher, how about this:
# gh-115874: segfaults when accessing module state in tp_dealloc. | |
# gh-115874: Segfault when accessing module state in tp_dealloc. | |
# The repro depends on multiple ref cycles; by importing | |
# typing, we implicitly create ref cycles between typing | |
# and copyreg. Without these cycles, the reproducer does | |
# not work. |
No-one chimed in, so we assume it is. If someone feels the urge to clarify the comment further, a follow-up PR can be made. |
Thanks @erlend-aasland for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…ythonGH-116204) (cherry picked from commit e2fcaf1) Co-authored-by: Erlend E. Aasland <[email protected]> Co-authored-by: Brandt Bucher <[email protected]>
GH-116955 is a backport of this pull request to the 3.12 branch. |
…H-116204) (#116955) (cherry picked from commit e2fcaf1) Co-authored-by: Erlend E. Aasland <[email protected]> Co-authored-by: Brandt Bucher <[email protected]>
…ython#116204) Co-authored-by: Brandt Bucher <[email protected]>
…ython#116204) Co-authored-by: Brandt Bucher <[email protected]>
…ython#116204) Co-authored-by: Brandt Bucher <[email protected]>
tp_dealloc
(itertools teedataobject clear) #115874