Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-127049: Fixasyncio.subprocess.Process race condition killing an unrelated process on Unix#127051

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
gschaffner wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromgschaffner:fix-asyncio-kill-race

Conversation

@gschaffner
Copy link

Proposal thatfixesGH-127049. The idea is to revertGH-121126 and re-fixGH-87744 in a way that doesn't introduceGH-127049. The proposed approach here is to change child watchers to behave closer to their analog on Windows (_WindowsSubprocessTransport), i.e. letsubprocess handle the PID lifetime management instead of havingsubprocess do the allocation andasyncio do the deallocation, i.e. follow the guidance of#86724 (comment).

In the_ThreadedChildWatcher case this borrows thewaitid +WNOWAIT idea from Trio. (See also#82811 (comment).) Note that in the_ThreadedChildWatcher case, while it would ideally be safe to just callPopen.wait in the thread instead of involvingwaitid +WNOWAIT,Popen currently has some thread-unsafeties, so runningPopen.wait orPopen.poll in the thread in practice resulted in unsafekill calls and brokentransport._process_exited(returncode=None) calls. See the longer commit message.

I have marked this as a draft because it does not yet have regression tests. Both cases (_PidfdChildWatcher and_ThreadedChildWatcher) can have (nearly-)deterministic (but consistent regardless) regression tests, but I am not sure how folks would want them implemented, as the reproducers I put together for the report involve monkeypatchingos.waitpid andos.kill (which is nontrivial in part becausesubprocess holds strong references toos.waitpid, and which will miss anyos.waitid calls made withoutWNOWAIT unless we patch that too).

Anyway, if this PR is pursued, I'd appreciate some help with adding tests. This is also my first PR proposed to CPython so any feedback/pointers are appreciated. :)

gpshead reacted with eyes emoji
…_signal in asyncio (python#121126)"This reverts the non-test changes of commitbd473aa.
Note that we call Popen.poll/wait in the event loop thread to avoidPopen's thread-unsafety. Without this workaround, when testing_ThreadedChildWatcher with the reproducer shared in the linked issue on mymachine:* Case 1 of the known race condition ignored inpythonGH-20010 is met (and an  unsafe kill call is issued) about 1 in 10 times.* The race conditionpythonGH-127050 is met (causing _process_exited's assert  returncode is not None to raise) about 1 in 30 times.
@ghost
Copy link

ghost commentedNov 20, 2024
edited by ghost
Loading

All commit authors signed the Contributor License Agreement.
CLA signed

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

Reviewers

@gpsheadgpsheadAwaiting requested review from gpsheadgpshead will be requested when the pull request is marked ready for reviewgpshead is a code owner

@1st11st1Awaiting requested review from 1st11st1 will be requested when the pull request is marked ready for review1st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov will be requested when the pull request is marked ready for reviewasvetlov is a code owner

@kumaraditya303kumaraditya303Awaiting requested review from kumaraditya303kumaraditya303 will be requested when the pull request is marked ready for reviewkumaraditya303 is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc will be requested when the pull request is marked ready for reviewwillingc is a code owner

Assignees

@gpsheadgpshead

Labels

None yet

Projects

None yet

Milestone

No milestone

2 participants

@gschaffner@gpshead

[8]ページ先頭

©2009-2025 Movatter.jp