Skip to content

Commit

Permalink
background: disable gc before forking
Browse files Browse the repository at this point in the history
Summary:
We encountered an issue where gc kicked in after forking the Python
process. This cause it to trigger some Rust drop logic which hung because some
cross thread locks were not in a good state. Let's just disable gc during the
fork and only reenable it in the parent process.

Reviewed By: quark-zju

Differential Revision: D22855986

fbshipit-source-id: c3e99fb000bcd4cc141848e6362bb7773d0aad3d
  • Loading branch information
DurhamG authored and facebook-github-bot committed Jul 31, 2020
1 parent 417d61f commit c35b808
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions eden/scm/edenscm/hgext/extutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import contextlib
import errno
import gc
import os
import subprocess
import time
Expand Down Expand Up @@ -55,6 +56,11 @@ def runbgcommand(cmd, env, shell=False, stdout=None, stderr=None):
# "os.fork()".
# 2. The "pid" variable cannot be used in the "finally" block.
try:
# Disable gc so the child process doesn't accidentally trigger it
# and try to collect native objects that might depend on locks held
# by other threads.
gc.disable()

# double-fork to completely detach from the parent process
# based on http://code.activestate.com/recipes/278731
pid = os.fork()
Expand Down Expand Up @@ -116,6 +122,7 @@ def runbgcommand(cmd, env, shell=False, stdout=None, stderr=None):
# mission accomplished, this child needs to exit and not
# continue the hg process here.
os._exit(returncode)
gc.enable()


def runshellcommand(script, env):
Expand Down

0 comments on commit c35b808

Please sign in to comment.