Skip to content
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

bpo-36820: Break unnecessary cycle in socket.py, codeop.py and dyld.py #13135

Merged
merged 5 commits into from Dec 6, 2019

Conversation

@mariocj89
Copy link
Contributor

mariocj89 commented May 6, 2019

Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the __traceback__ attribute.

https://bugs.python.org/issue36820

Automerge-Triggered-By: @pablogsal

@matrixise matrixise changed the title bpo-36820: Break unnecesary cycle in socket.py, codeop.py and dyld.py bpo-36820: Break unnecessary cycle in socket.py, codeop.py and dyld.py May 6, 2019
@pablogsal pablogsal self-assigned this May 6, 2019
@pablogsal pablogsal self-requested a review May 6, 2019
@auvipy
auvipy approved these changes May 31, 2019
@mariocj89

This comment has been minimized.

Copy link
Contributor Author

mariocj89 commented Oct 20, 2019

From offline conversation @pablogsal, this was waiting on trying to get a generic way to detect these kinds of cycles. It seemed to be much harder than initially thought.
As you suggested back in the day, do you want me to remove the tests here and land this?
We can look at detecting cycles in a generic way in a separate effort/PR.

pablogsal added a commit that referenced this pull request Nov 19, 2019
…nces of creating cycles (GH-17246)

Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles.

See for example GH-13135
jacobneiltaylor added a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
…nces of creating cycles (pythonGH-17246)

Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles.

See for example pythonGH-13135
mariocj89 added 5 commits May 6, 2019
The cycle happens when an exception is raised in
`socket.create_connection` as it saves the exception in a variable and
then re-raise it. By removing the name when the exception is raised we
remove this cycle. We cannot just remove the name before as in the happy
path since we need the exception to be raised.
As the exceptions were being saved in a different name it was
generating a cycle since it was own through the `__traceback__`.
By unsetting them we can collect the object earlier without the need of
waiting for the gc.
As the exceptions were being saved in a different name it was
generating a cycle since it was own through the `__traceback__`.
By unsetting them we can collect the object earlier without the need of
waiting for the gc.
@mariocj89 mariocj89 force-pushed the mariocj89:pu/socket-cycle-on-err branch from adfd53a to be7ebe0 Dec 6, 2019
Copy link
Member

pablogsal left a comment

LGTM 🚀

@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Dec 6, 2019

@mariocj89: Status check is done, and it's a success .

@miss-islington miss-islington merged commit b64334c into python:master Dec 6, 2019
4 checks passed
4 checks passed
Azure Pipelines PR #20191206.9 succeeded
Details
bedevere/issue-number Issue number 36820 found
Details
bedevere/news News entry found in Misc/NEWS.d
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Dec 6, 2019

Thanks @mariocj89 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒🤖

@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Dec 6, 2019

Thanks @mariocj89 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒🤖

@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Dec 6, 2019

GH-17485 is a backport of this pull request to the 3.7 branch.

miss-islington added a commit to miss-islington/cpython that referenced this pull request Dec 6, 2019
pythonGH-13135)

Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute.

https://bugs.python.org/issue36820

Automerge-Triggered-By: @pablogsal
(cherry picked from commit b64334c)

Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Dec 6, 2019

GH-17486 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit to miss-islington/cpython that referenced this pull request Dec 6, 2019
pythonGH-13135)

Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute.

https://bugs.python.org/issue36820

Automerge-Triggered-By: @pablogsal
(cherry picked from commit b64334c)

Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
miss-islington added a commit that referenced this pull request Dec 6, 2019
GH-13135)

Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute.

https://bugs.python.org/issue36820

Automerge-Triggered-By: @pablogsal
(cherry picked from commit b64334c)

Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
miss-islington added a commit that referenced this pull request Dec 6, 2019
GH-13135)

Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute.

https://bugs.python.org/issue36820

Automerge-Triggered-By: @pablogsal
(cherry picked from commit b64334c)

Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.