changeset 30421:47de34f79f93

worker: wait worker pid explicitly Before this patch, waitforworkers uses os.wait() to collect child workers, and only wait len(pids) processes. This can have serious issues if other code spawns new processes and does not reap them: 1. worker.py may get wrong exit code and kill innocent workers. 2. worker.py may continue without waiting for all workers to complete. This patch fixes the issue by using waitpid to wait worker pid explicitly. However, this patch introduces a new issue: worker failure may not be handled immediately. The issue will be addressed in next patches.
author Jun Wu <quark@fb.com>
date Thu, 28 Jul 2016 20:51:20 +0100
parents 7a5d6e2fd2d5
children 7bc25549e084
files mercurial/worker.py
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/worker.py	Thu Jul 28 20:49:57 2016 +0100
+++ b/mercurial/worker.py	Thu Jul 28 20:51:20 2016 +0100
@@ -98,8 +98,8 @@
                 if err.errno != errno.ESRCH:
                     raise
     def waitforworkers():
-        for _pid in pids:
-            st = _exitstatus(os.wait()[1])
+        for pid in pids:
+            st = _exitstatus(os.waitpid(pid, 0)[1])
             if st and not problem[0]:
                 problem[0] = st
                 killworkers()