Skip to content

Commit c35b808

Browse files
DurhamGfacebook-github-bot
authored andcommitted
background: disable gc before forking
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
1 parent 417d61f commit c35b808

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

eden/scm/edenscm/hgext/extutil.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import contextlib
1111
import errno
12+
import gc
1213
import os
1314
import subprocess
1415
import time
@@ -55,6 +56,11 @@ def runbgcommand(cmd, env, shell=False, stdout=None, stderr=None):
5556
# "os.fork()".
5657
# 2. The "pid" variable cannot be used in the "finally" block.
5758
try:
59+
# Disable gc so the child process doesn't accidentally trigger it
60+
# and try to collect native objects that might depend on locks held
61+
# by other threads.
62+
gc.disable()
63+
5864
# double-fork to completely detach from the parent process
5965
# based on http://code.activestate.com/recipes/278731
6066
pid = os.fork()
@@ -116,6 +122,7 @@ def runbgcommand(cmd, env, shell=False, stdout=None, stderr=None):
116122
# mission accomplished, this child needs to exit and not
117123
# continue the hg process here.
118124
os._exit(returncode)
125+
gc.enable()
119126

120127

121128
def runshellcommand(script, env):

0 commit comments

Comments
 (0)