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

Jun Wu quark at fb.com
Fri Nov 11 22:11:33 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 05485a528446de24eb8b81819f66ad36f0730802
# Parent  e1a77dd540d28358884478fe5cb7d9ba1b41cef3
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 05485a528446
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
@@ -96,6 +96,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