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

Remove last exception's references if any #59

Merged
merged 2 commits into from
Mar 18, 2021

Conversation

anton-ryzhov
Copy link
Contributor

code module used underneath stores exception details in sys module.

That creates a memory leak in case of exception in manhole session. This exception encapsulates entire session with all stack frames with their locals and manhole internals (such as ManholeConsole instance and connection file wrapper).

Simple test. Call this via manhole and target process will be 100Mb bigger even after disconnect:

>>> padding = ' ' * 100 * 1024**2
>>> assert 0 
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AssertionError
>>> ^D
now exiting ManholeConsole...

@anton-ryzhov anton-ryzhov changed the title Remove last exception's data if any Remove last exception's references if any Mar 13, 2021
finally:
for attribute in ['last_type', 'last_value', 'last_traceback']:
try:
delattr(sys, attribute)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to set to None instead? This would trigger AttributeErrors - afaik the python docs give the impression that these attributes would always be there.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@anton-ryzhov anton-ryzhov Mar 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they're not defined by default. So I'm reverting them to the original state

@ionelmc
Copy link
Owner

ionelmc commented Mar 17, 2021

Can you also update changelog/authors.rst ?

@anton-ryzhov
Copy link
Contributor Author

Like this?

@codecov
Copy link

codecov bot commented Mar 17, 2021

Codecov Report

Merging #59 (90bbfff) into master (9837614) will decrease coverage by 0.87%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #59      +/-   ##
==========================================
- Coverage   83.98%   83.10%   -0.88%     
==========================================
  Files           6        6              
  Lines        1255     1261       +6     
  Branches      134      135       +1     
==========================================
- Hits         1054     1048       -6     
- Misses        164      175      +11     
- Partials       37       38       +1     
Impacted Files Coverage Δ
src/manhole/__init__.py 91.04% <100.00%> (-0.88%) ⬇️
tests/helper.py 74.33% <0.00%> (-2.66%) ⬇️
tests/test_manhole.py 90.97% <0.00%> (-0.49%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9837614...90bbfff. Read the comment docs.

@ionelmc ionelmc merged commit 16596e7 into ionelmc:master Mar 18, 2021
@ionelmc
Copy link
Owner

ionelmc commented Mar 18, 2021

Yes, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants