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

subprocess - Fix a bug where trio isn't notified about pidfd closes #2209

Merged
merged 3 commits into from
Jan 12, 2022

Conversation

tjstum
Copy link
Member

@tjstum tjstum commented Jan 12, 2022

If you have

  1. Task A blocks in Process.wait
  2. The child process exits
  3. Task B calls Process.returncode

(3) will close the pidfd, but nothing will ever wake up Task A, since
trio wasn't notified.

I noticed this when I wrote a deliver_cancel function that was slow
enough that the child actually exited before the call to
Process.returncode. In the default _posix_deliver_cancel, everything is so
fast that the usual ordering is that (3) comes before (2), and there
isn't an early call to _pidfd_close.

This fixes the bug by ensuring we notify trio about closing the pidfd
when we do it!

If you have
  1. Task A blocks in `Process.wait`
  2. The child process exits
  3. Task B calls `Process.returncode`

(3) will close the pidfd, but nothing will ever wake up Task A, since
trio wasn't notified.

I noticed this when I wrote a `deliver_cancel` function that was slow
enough that the child actually exited before the call to
`Process.returncode`. In the default `_posix_deliver_cancel`, everything is so
fast that the usual ordering is that (3) comes before (2), and there
isn't an early call to `_pidfd_close`.

This fixes the bug by ensuring we notify trio about closing the pidfd
when we do it!
@tjstum tjstum requested review from njsmith and oremanj January 12, 2022 21:15
@codecov
Copy link

codecov bot commented Jan 12, 2022

Codecov Report

Merging #2209 (18a850c) into master (147a545) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2209      +/-   ##
==========================================
+ Coverage   99.51%   99.55%   +0.04%     
==========================================
  Files         114      114              
  Lines       14780    14803      +23     
  Branches     2346     2349       +3     
==========================================
+ Hits        14708    14737      +29     
+ Misses         47       44       -3     
+ Partials       25       22       -3     
Impacted Files Coverage Δ
trio/_subprocess.py 96.95% <100.00%> (+0.06%) ⬆️
trio/tests/test_subprocess.py 100.00% <100.00%> (ø)
trio/tests/test_ssl.py 99.58% <0.00%> (+0.55%) ⬆️
trio/_highlevel_ssl_helpers.py 100.00% <0.00%> (+11.76%) ⬆️

@oremanj
Copy link
Member

oremanj commented Jan 12, 2022

Please add a newsfragment for this change.

@oremanj oremanj merged commit 4edfd41 into python-trio:master Jan 12, 2022
@tjstum tjstum deleted the fixprochang branch February 2, 2022 15:37
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