[PATCH 2 of 8 V5] worker: wait worker pid explicitly

Jun Wu quark at fb.com
Mon Nov 14 21:39:05 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1469735480 -3600
#      Thu Jul 28 20:51:20 2016 +0100
# Node ID 946a4a33ad2fbb4a060af6f32f0a96a63d01a6e8
# Parent  7a81772420713713fb372966a9018c20083beaed
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 946a4a33ad2f
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.

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -99,6 +99,6 @@ def _posixworker(ui, func, staticargs, a
                     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


More information about the Mercurial-devel mailing list