[issue21491] race condition in SocketServer.py ForkingMixIn collect_children
Charles-François Natali added the comment: Committed, thanks! -- resolution: - fixed stage: patch review - resolved status: open - closed type: resource usage - behavior versions: +Python 3.3, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21491 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21491] race condition in SocketServer.py ForkingMixIn collect_children
Roundup Robot added the comment: New changeset aa5e3f7a5501 by Charles-François Natali in branch '2.7': Issue #21491: SocketServer: Fix a race condition in child processes reaping. http://hg.python.org/cpython/rev/aa5e3f7a5501 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21491 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21491] race condition in SocketServer.py ForkingMixIn collect_children
Roundup Robot added the comment: New changeset 2a7375bd09f9 by Charles-François Natali in branch '3.4': Issue #21491: socketserver: Fix a race condition in child processes reaping. http://hg.python.org/cpython/rev/2a7375bd09f9 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21491 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21491] race condition in SocketServer.py ForkingMixIn collect_children
Roundup Robot added the comment: New changeset ae0b572ced20 by Charles-François Natali in branch 'default': Issue #21491: socketserver: Fix a race condition in child processes reaping. http://hg.python.org/cpython/rev/ae0b572ced20 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21491 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21491] race condition in SocketServer.py ForkingMixIn collect_children
Charles-François Natali added the comment: Here's a patch fixing both issues. -- keywords: +needs review, patch nosy: +haypo, pitrou stage: - patch review Added file: http://bugs.python.org/file35508/socketserver_reap.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21491 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21491] race condition in SocketServer.py ForkingMixIn collect_children
New submission from Ids van der Molen: collect_children routine in SocketServer.py contains two possible race conditions. First one is in while loop while len(self.active_children) = self.max_children:. If status of child is collected outside of Socket server (for example in signal handler or something), then the variable self.active_children will not match actual child processes and the os.waitpid(0, 0) within the while loop will raise os.error, errno=10 (ECHILD) No Child Processes. self.active_children should be emptied in this case, otherwise you'll end up with an endless loop comsuming 100% CPU (as happened to us). The second possible race condition is below in the collect_children routine in the for child in self.active_children which contains a statement self.active_children.remove(pid) which would modify the iterator. I do not now about python 2.7, but before this would result in incorrect iteration. Original code: for child in self.active_children: try: pid, status = os.waitpid(child, os.WNOHANG) except os.error: pid = None if not pid: continue try: self.active_children.remove(pid) except ValueError, e: raise ValueError('%s. x=%d and list=%r' % (e.message, pid, self.active_children)) Fixed code: to_remove = [] for child in self.active_children: try: pid, status = os.waitpid(child, os.WNOHANG) except os.error: pid = None if not pid: continue to_remove.append(pid) for pid in to_remove: try: self.active_children.remove(pid) except ValueError, e: raise ValueError('%s. x=%d and list=%r' % (e.message, pid, self.active_children)) -- components: Library (Lib) messages: 218414 nosy: idsvandermolen priority: normal severity: normal status: open title: race condition in SocketServer.py ForkingMixIn collect_children type: resource usage versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21491 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21491] race condition in SocketServer.py ForkingMixIn collect_children
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +neologix ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21491 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com