[Updated] D8497: procutil: always waiting on child processes to prevent zombies with 'hg serve'

rdamazio (Rodrigo Damazio Bovendorp) phabricator at mercurial-scm.org
Thu May 7 15:02:23 UTC 2020


Closed by commit rHG38e0c006b0ae: procutil: always waiting on child processes to prevent zombies with 'hg serve' (authored by rdamazio).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8497?vs=21274&id=21281

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8497/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8497

AFFECTED FILES
  hg
  mercurial/utils/procutil.py

CHANGE DETAILS

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -16,6 +16,7 @@
 import signal
 import subprocess
 import sys
+import threading
 import time
 
 from ..i18n import _
@@ -604,6 +605,14 @@
             pid = os.fork()
             if pid:
                 if not ensurestart:
+                    # Even though we're not waiting on the child process,
+                    # we still must call waitpid() on it at some point so
+                    # it's not a zombie/defunct. This is especially relevant for
+                    # chg since the parent process won't die anytime soon.
+                    # We use a thread to make the overhead tiny.
+                    def _do_wait():
+                        os.waitpid(pid, 0)
+                    threading.Thread(target=_do_wait, daemon=True).start()
                     return
                 # Parent process
                 (_pid, status) = os.waitpid(pid, 0)
diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # mercurial - scalable distributed SCM
 #



To: rdamazio, #hg-reviewers
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200507/392fb388/attachment-0002.html>


More information about the Mercurial-patches mailing list