Merge lp:~cjwatson/lazr.restful/traceback-reference-cycle into lp:lazr.restful

Proposed by Colin Watson
Status: Merged
Merged at revision: 294
Proposed branch: lp:~cjwatson/lazr.restful/traceback-reference-cycle
Merge into: lp:lazr.restful
Diff against target: 57 lines (+22/-13)
2 files modified
NEWS.rst (+5/-0)
src/lazr/restful/_resource.py (+17/-13)
To merge this branch: bzr merge lp:~cjwatson/lazr.restful/traceback-reference-cycle
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+402748@code.launchpad.net

Commit message

Avoid traceback reference cycle in ReadWriteResource.__call__.

Description of the change

`sys.exc_info()` called from `ReadWriteResource.__call__` returns a tuple containing the exception's traceback object, which has a reference to the `ReadWriteResource.__call__` frame. Storing that in a local variable creates a reference cycle. Clear that variable in a `finally` block to avoid this.

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.rst'
--- NEWS.rst 2021-02-18 11:03:23 +0000
+++ NEWS.rst 2021-05-14 09:15:23 +0000
@@ -2,6 +2,11 @@
2NEWS for lazr.restful2NEWS for lazr.restful
3=====================3=====================
44
51.0.2
6=====
7
8Avoid traceback reference cycle in ``ReadWriteResource.__call__``.
9
51.0.1 (2021-02-18)101.0.1 (2021-02-18)
6==================11==================
712
813
=== modified file 'src/lazr/restful/_resource.py'
--- src/lazr/restful/_resource.py 2021-01-21 11:43:07 +0000
+++ src/lazr/restful/_resource.py 2021-05-14 09:15:23 +0000
@@ -940,20 +940,24 @@
940 self.request.response.setHeader("Allow", allow_string)940 self.request.response.setHeader("Allow", allow_string)
941 except Exception as e:941 except Exception as e:
942 exception_info = sys.exc_info()942 exception_info = sys.exc_info()
943 view = getMultiAdapter((e, self.request), name="index.html")
944 try:943 try:
945 ws_view = IWebServiceExceptionView(view)944 view = getMultiAdapter((e, self.request), name="index.html")
946 except TypeError:945 try:
947 # There's a view for this exception, but it's not one946 ws_view = IWebServiceExceptionView(view)
948 # we can understand. It was probably designed for a947 except TypeError:
949 # web application rather than a web service. We'll948 # There's a view for this exception, but it's not one we
950 # re-raise the exception, let the publisher look up949 # can understand. It was probably designed for a web
951 # the view, and hopefully handle it better. Note the careful950 # application rather than a web service. We'll re-raise
952 # reraising that ensures the original traceback is preserved.951 # the exception, let the publisher look up the view, and
953 if six.PY3:952 # hopefully handle it better. Note the careful
954 six.raise_from(exception_info[1], None)953 # reraising that ensures the original traceback is
955 else:954 # preserved.
956 six.reraise(*exception_info)955 if six.PY3:
956 six.raise_from(exception_info[1], None)
957 else:
958 six.reraise(*exception_info)
959 finally:
960 del exception_info
957961
958 self.request.response.setStatus(ws_view.status)962 self.request.response.setStatus(ws_view.status)
959 if ws_view.status // 100 == 4:963 if ws_view.status // 100 == 4:

Subscribers

People subscribed via source and target branches