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

make sure coroutine locals are promptly destroyed #1864

Merged
merged 6 commits into from
Jan 31, 2021

Conversation

richardsheridan
Copy link
Contributor

@richardsheridan richardsheridan commented Jan 12, 2021

This PR fixes a "bug" where unrolled_run hangs on to Cancelled tracebacks too long. They essentially persist until the next exception is thrown out of a task, which may be an indefinite period of time. This was not cleaned up with the earlier cyclic garbage bugfix #1770 because it is not cyclic garbage; it's actually a strong reference that lives unnecessarily long.

(Thinking out loud here) This is just the minimum possible fix. There are actually a number of locals akin to final_outcome in unrolled_run that may live up to _MAX_TIMEOUT seconds and contain references to tasks and potentially to hefty objects, but I haven't actually observed any issues along those lines yet. Scattering del statements everywhere is probably untenable, but factoring chunks of unrolled_run into function calls would "automate" that kind of cleanup, at the cost of some overhead.

@codecov
Copy link

codecov bot commented Jan 12, 2021

Codecov Report

Merging #1864 (8170b42) into master (61ee58a) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1864      +/-   ##
==========================================
+ Coverage   99.59%   99.64%   +0.04%     
==========================================
  Files         114      114              
  Lines       14549    14569      +20     
  Branches     1110     1110              
==========================================
+ Hits        14490    14517      +27     
+ Misses         42       36       -6     
+ Partials       17       16       -1     
Impacted Files Coverage Δ
trio/_core/_run.py 100.00% <100.00%> (ø)
trio/_core/tests/test_run.py 100.00% <100.00%> (ø)
trio/testing/_check_streams.py 99.33% <0.00%> (+0.66%) ⬆️
trio/tests/test_socket.py 100.00% <0.00%> (+0.81%) ⬆️

@richardsheridan
Copy link
Contributor Author

richardsheridan commented Jan 12, 2021

I totally meant to do a red-green test with these commits... yes...

@oremanj
Copy link
Member

oremanj commented Jan 12, 2021

FWIW, I do think scattering del statements is entirely tenable. I'd be less excited about adding function call overhead on every task step.

Copy link
Member

@belm0 belm0 left a comment

Choose a reason for hiding this comment

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

worth a newsfragment?

@richardsheridan
Copy link
Contributor Author

I think I got em all, but I would appreciate a double-check!

@belm0
Copy link
Member

belm0 commented Jan 17, 2021

I think I got em all, but I would appreciate a double-check!

would it be hard to expand tests to cover the additional explicit deletes?

@richardsheridan
Copy link
Contributor Author

Well I haven't been able to come up with a good test so far, let me stew on it another week. Also TIL except ... as exc blocks delete exc at the end of the block, so two of those are technically unnecessary!

@belm0
Copy link
Member

belm0 commented Jan 31, 2021

Well I haven't been able to come up with a good test so far, let me stew on it another week. Also TIL except ... as exc blocks delete exc at the end of the block, so two of those are technically unnecessary!

So just keeping track, the deletions of msg, task, next_send, next_send_fn don't have test coverage? Consider adding a TODO in the code.

@belm0
Copy link
Member

belm0 commented Jan 31, 2021

not sure how to trigger rebuild on sourcehut, will try close & re-open of PR

@belm0 belm0 closed this Jan 31, 2021
@belm0 belm0 reopened this Jan 31, 2021
@belm0 belm0 merged commit 970cd16 into python-trio:master Jan 31, 2021
@richardsheridan richardsheridan deleted the del_tb_strongref branch February 2, 2021 11:48
belm0 pushed a commit that referenced this pull request Jul 18, 2021
from MultiErrorCatcher.__exit__, _multierror.copy_tb, MultiError.filter, CancelScope.__exit__, and NurseryManager.__aexit__ methods. This was nearly impossible to catch until #1864 landed so it wasn't cleaned up in #1805 (or during the live stream: https://www.youtube.com/watch?v=E_jvJVYXUAk).
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.

3 participants