-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Improve FastChildWatcher with WNOWAIT? #70124
Comments
The problem with FastChildWatcher lies in the fact that it can accidentally reap processes that it doesn't watch. However, os module includes waitid function (since Python 3.3), and it has WNOWAIT flags, which means "return status, let process remain waitable (=don't reap)". What do you think, can this feature fix the problem with FastChildWatcher? |
Hm... Looks like this wouldn't work unless we also implemented the waitid() (note: 'id', not 'pid') syscall, as waitpid() doesn't support this flag (e.g. https://bugzilla.redhat.com/show_bug.cgi?id=840782). |
Oh, hm, we do seem to have os.waitid() but not on OS X... Well that makes producing a reasonable patch much more complicated. Maybe you want to add a 3rd ChildWatcher just for Linux (or just for platforms that have os.waitid)? (If so, please submit a PR to https://github.com/python/asyncio, which we use as "upstream".) |
|
@graingert Or maybe we should close this as there have been no comments since 2015 and you seem to want to get rid of child watchers? |
PidfdChildWatcher doesn't avoid threads. It uses the main thread event loop. |
We probably want to to use WNOWAIT on all the child watchers if we can support it. @njsmith had a comment somewhere about it |
here's the comment: #82811 (comment) you'd have to fix everywhere that uses |
I wonder if we can get @gpshead interested in this issue… |
currently to fix class Pid:
def __init__(self, pid):
self._pid = pid
def pidno(self):
return self._pid
def closed(self):
return self._pid != -1
def reap(self):
with self._lock: # _pyio.FileIO is probably missing this lock
pid = self._pid
self._pid = -1
os.waitpid(pid, ...) |
so is there really anything to fix for this specific issue? FastChildWatcher isn't supposed to be safe. |
Don't describe that as "fixing" But this doesn't really have anything to do with this issue, it belongs in its own feature request with its own problem statement. We do still have very minor race conditions in our stdlib libraries that use waitpid. As Nathaniel noted in the linked comment: It only solves the problem so long as code is using the specific APIs that do the non-waiting waitid, lock, re-check & actually-wait dance behind the scenes. It'd be a minor improvement if we actually did that. Why doesn't this come often up as a real problem? In general OSes attempt to avoid this scenario by not recycling PIDs rapidly so that running programs do not wind up seeing other processes that have reused another processes pid when they make their pid based calls. With a modern 32bit PID space this is doable even if you have a 1000 CPU thread system. It works well enough until someone starts an antagonistic forkbomb or threadbomb to rapidly consume and throw away PIDs. (yet another form of denial of service, intentional or not) So it's primarily a way to be safer with process management in the face of things that aren't supposed to happen. But by the time that has happened a lot is likely to go wrong on the system anyways so this usually isn't the top priority. |
FWIW before proposing solutions we should consider if this is even an real issue which cannot be solved with other solutions like using an alternate existing watcher implementation. The current state of child watcher system is complicated and almost all child watcher except |
Yep there's really no need to configure a child watcher for advanced users, they can copy the subprocess transport code and use their own OS facilities that they need |
I'm closing this as there isn't anything actionable here, and it is documented that it is unsafe. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: