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
1=== modified file 'NEWS.rst'
2--- NEWS.rst 2021-02-18 11:03:23 +0000
3+++ NEWS.rst 2021-05-14 09:15:23 +0000
4@@ -2,6 +2,11 @@
5 NEWS for lazr.restful
6 =====================
7
8+1.0.2
9+=====
10+
11+Avoid traceback reference cycle in ``ReadWriteResource.__call__``.
12+
13 1.0.1 (2021-02-18)
14 ==================
15
16
17=== modified file 'src/lazr/restful/_resource.py'
18--- src/lazr/restful/_resource.py 2021-01-21 11:43:07 +0000
19+++ src/lazr/restful/_resource.py 2021-05-14 09:15:23 +0000
20@@ -940,20 +940,24 @@
21 self.request.response.setHeader("Allow", allow_string)
22 except Exception as e:
23 exception_info = sys.exc_info()
24- view = getMultiAdapter((e, self.request), name="index.html")
25 try:
26- ws_view = IWebServiceExceptionView(view)
27- except TypeError:
28- # There's a view for this exception, but it's not one
29- # we can understand. It was probably designed for a
30- # web application rather than a web service. We'll
31- # re-raise the exception, let the publisher look up
32- # the view, and hopefully handle it better. Note the careful
33- # reraising that ensures the original traceback is preserved.
34- if six.PY3:
35- six.raise_from(exception_info[1], None)
36- else:
37- six.reraise(*exception_info)
38+ view = getMultiAdapter((e, self.request), name="index.html")
39+ try:
40+ ws_view = IWebServiceExceptionView(view)
41+ except TypeError:
42+ # There's a view for this exception, but it's not one we
43+ # can understand. It was probably designed for a web
44+ # application rather than a web service. We'll re-raise
45+ # the exception, let the publisher look up the view, and
46+ # hopefully handle it better. Note the careful
47+ # reraising that ensures the original traceback is
48+ # preserved.
49+ if six.PY3:
50+ six.raise_from(exception_info[1], None)
51+ else:
52+ six.reraise(*exception_info)
53+ finally:
54+ del exception_info
55
56 self.request.response.setStatus(ws_view.status)
57 if ws_view.status // 100 == 4:

Subscribers

People subscribed via source and target branches