Merge lp:~cjwatson/storm/py3-traceback-reference-cycles into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 572
Proposed branch: lp:~cjwatson/storm/py3-traceback-reference-cycles
Merge into: lp:storm
Diff against target: 36 lines (+16/-4)
2 files modified
NEWS (+8/-0)
storm/exceptions.py (+8/-4)
To merge this branch: bzr merge lp:~cjwatson/storm/py3-traceback-reference-cycles
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Storm Developers Pending
Review via email: mp+402726@code.launchpad.net

Commit message

Avoid traceback reference cycles when wrapping exceptions.

Description of the change

`wrap_exceptions` stored the original exception's traceback in a local variable, but the traceback in turn contains a reference to that frame, creating a reference cycle. The situation is worse on Python 3, because the original exception also has the associated traceback as a `__traceback__` attribute, producing more complicated reference cycles. Delete these local variables before returning to avoid leaking memory over time.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2021-04-19 09:52:52 +0000
+++ NEWS 2021-05-13 23:27:28 +0000
@@ -1,3 +1,11 @@
10.26
2====
3
4Bug fixes
5---------
6
7- Avoid traceback reference cycles when wrapping exceptions.
8
10.25 (2021-04-19)90.25 (2021-04-19)
2=================10=================
311
412
=== modified file 'storm/exceptions.py'
--- storm/exceptions.py 2019-06-26 07:16:54 +0000
+++ storm/exceptions.py 2021-05-13 23:27:28 +0000
@@ -178,8 +178,12 @@
178 # As close to "raise wrapped.with_traceback(tb) from e" as178 # As close to "raise wrapped.with_traceback(tb) from e" as
179 # we can manage, but without causing syntax errors on179 # we can manage, but without causing syntax errors on
180 # various versions of Python.180 # various versions of Python.
181 if six.PY2:181 try:
182 six.reraise(wrapped, None, tb)182 if six.PY2:
183 else:183 six.reraise(wrapped, None, tb)
184 six.raise_from(wrapped.with_traceback(tb), e)184 else:
185 six.raise_from(wrapped.with_traceback(tb), e)
186 finally:
187 # Avoid traceback reference cycles.
188 del wrapped, tb
185 raise189 raise

Subscribers

People subscribed via source and target branches

to status/vote changes: