Skip to content

bpo-35721: Close socket pair if Popen in _UnixSubprocessTransport fails #11553

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

Merged
merged 1 commit into from
May 20, 2019

Conversation

niklasf
Copy link
Contributor

@niklasf niklasf commented Jan 14, 2019

This slightly expands an existing test case test_popen_error to trigger a ResourceWarning and fixes it.

https://bugs.python.org/issue35721

universal_newlines=False, bufsize=bufsize, **kwargs)
if stdin_w is not None:
self._proc.stdin = open(stdin_w.detach(), 'wb', buffering=bufsize)
stdin.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move the line before open() call.
It saves 1 open file descriptor.
Not a very big deal but why not?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I even understand this code :) What's it for? Why does monkeypatching self._proc.stdin work?

Copy link
Contributor

Choose a reason for hiding this comment

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

@1st1 please read a code comment at the begin of the method.
AIX requires to make stdin a socket pair (I love all Unix flavors and their differences).
proc.stdin should be a writable file-like object.
open() creates a file object from write-fd of created socket pair.

It exists in asyncio starting from very old times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asvetlov: Good point. I suppose since open(stdin_w.detach(), ...) cannot fail I should have kept the order.

Copy link
Member

Choose a reason for hiding this comment

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

@1st1 please read a code comment at the begin of the method.

Yeah, that's what I did first. The comment doesn't explain why we pass the read end of the pipe to Popen initially (I see that we then monkey-patch it to the write end).

It exists in asyncio starting from very old times.

I've no problem with the code or this PR, but I wish that the comment is a bit more elaborate.

Copy link
Contributor

Choose a reason for hiding this comment

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

@1st1 you know, I'm bad in comment writing, sorry.
Would you propose exact text?

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@niklasf niklasf force-pushed the socket-pair-leak-35721 branch from 3b43fd0 to e6a1cf3 Compare January 16, 2019 20:33
@niklasf
Copy link
Contributor Author

niklasf commented Jan 16, 2019

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@asvetlov: please review the changes made to this pull request.

@niklasf
Copy link
Contributor Author

niklasf commented May 18, 2019

Is there anything I can do to help this move along?

@csabella csabella requested a review from asvetlov May 18, 2019 19:38
@miss-islington
Copy link
Contributor

Sorry, I can't merge this PR. Reason: Base branch was modified. Review and try the merge again..

@miss-islington miss-islington merged commit 9932fd9 into python:master May 20, 2019
@miss-islington
Copy link
Contributor

Thanks @niklasf for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 20, 2019
…ls (pythonGH-11553)

This slightly expands an existing test case `test_popen_error` to trigger a `ResourceWarning` and fixes it.

https://bugs.python.org/issue35721
(cherry picked from commit 9932fd9)

Co-authored-by: Niklas Fiekas <[email protected]>
@bedevere-bot
Copy link

GH-13439 is a backport of this pull request to the 3.7 branch.

@asvetlov
Copy link
Contributor

Let's land it.
Thanks!

miss-islington added a commit that referenced this pull request May 20, 2019
…ls (GH-11553)

This slightly expands an existing test case `test_popen_error` to trigger a `ResourceWarning` and fixes it.

https://bugs.python.org/issue35721
(cherry picked from commit 9932fd9)

Co-authored-by: Niklas Fiekas <[email protected]>
@niklasf
Copy link
Contributor Author

niklasf commented May 20, 2019

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.

6 participants