mercurial/chgserver.py
changeset 45035 3862de62d5cf
parent 44867 8e8fd938ca07
child 45185 a17454a189d1
--- a/mercurial/chgserver.py	Thu Jul 02 19:54:44 2020 +0200
+++ b/mercurial/chgserver.py	Fri Jul 03 13:45:59 2020 +0530
@@ -442,7 +442,20 @@
             if newfp is not fp:
                 newfp.close()
             # restore original fd: fp is open again
-            os.dup2(fd, fp.fileno())
+            try:
+                os.dup2(fd, fp.fileno())
+            except OSError as err:
+                # According to issue6330, running chg on heavy loaded systems
+                # can lead to EBUSY. [man dup2] indicates that, on Linux,
+                # EBUSY comes from a race condition between open() and dup2().
+                # However it's not clear why open() race occurred for
+                # newfd=stdin/out/err.
+                self.ui.log(
+                    b'chgserver',
+                    b'got %s while duplicating %s\n',
+                    stringutil.forcebytestr(err),
+                    fn,
+                )
             os.close(fd)
             setattr(self, cn, ch)
             setattr(ui, fn, fp)