Skip to content

gh-151179: Fix pidfd leak in asyncio _PidfdChildWatcher#151186

Open
deadlovelll wants to merge 3 commits into
python:mainfrom
deadlovelll:gh-151179-pidfd-leak
Open

gh-151179: Fix pidfd leak in asyncio _PidfdChildWatcher#151186
deadlovelll wants to merge 3 commits into
python:mainfrom
deadlovelll:gh-151179-pidfd-leak

Conversation

@deadlovelll

Copy link
Copy Markdown
Contributor

_PidfdChildWatcher._do_wait() left os.close(pidfd) outside the cleanup path. The pidfd leaked when waitpid() raising anything other than ChildProcessError. Moving os.close() into a finally block closes the descriptor while still letting the exception propagate.

For more details see gh-151179

Comment thread Lib/asyncio/unix_events.py Outdated
returncode = waitstatus_to_exitcode(status)

os.close(pidfd)
try:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why adding nested exception handler? You could just put os.close in finally block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point - fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants