[PATCH STABLE] worker: wait worker pid explicitly

Jun Wu quark at fb.com
Fri Jul 22 15:50:48 EDT 2016

# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1469216267 -3600
#      Fri Jul 22 20:37:47 2016 +0100
# Node ID 74d799c4781183b539aedd93530f0e5fa06839cc
# Parent  d3df009ab1175a6792549b51ae66486dd98f398b
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 74d799c47811
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.

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -112,8 +112,8 @@ def _posixworker(ui, func, staticargs, a
                 if err.errno != errno.ESRCH:
     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

More information about the Mercurial-devel mailing list