changeset 35426:60f2a215faa7

workers: don't use backgroundfilecloser in threads This disables background file closing when in not in main thread Test Plan: Ran pull, update, sparse commands and watched the closer threads created and destroyed in procexp.exe ran test on CentOS. No tests broken compared to the base Differential Revision: https://phab.mercurial-scm.org/D1457
author Wojciech Lis <wlis@fb.com>
date Mon, 11 Dec 2017 16:51:13 -0800
parents 702e6d2642e7
children 02b36e860e0b
files mercurial/vfs.py
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/vfs.py	Fri Dec 15 08:47:28 2017 -0800
+++ b/mercurial/vfs.py	Mon Dec 11 16:51:13 2017 -0800
@@ -277,8 +277,12 @@
         to ``__call__``/``open`` to result in the file possibly being closed
         asynchronously, on a background thread.
         """
-        # This is an arbitrary restriction and could be changed if we ever
-        # have a use case.
+        # Sharing backgroundfilecloser between threads is complex and using
+        # multiple instances puts us at risk of running out of file descriptors
+        # only allow to use backgroundfilecloser when in main thread.
+        if not isinstance(threading.currentThread(), threading._MainThread):
+            yield
+            return
         vfs = getattr(self, 'vfs', self)
         if getattr(vfs, '_backgroundfilecloser', None):
             raise error.Abort(
@@ -413,7 +417,8 @@
                                     ' valid for checkambig=True') % mode)
             fp = checkambigatclosing(fp)
 
-        if backgroundclose:
+        if (backgroundclose and
+                isinstance(threading.currentThread(), threading._MainThread)):
             if not self._backgroundfilecloser:
                 raise error.Abort(_('backgroundclose can only be used when a '
                                   'backgroundclosing context manager is active')