D9997: remotefilelog: rework workaround for sshpeer deadlocks

valentin.gatienbaron (Valentin Gatien-Baron) phabricator at mercurial-scm.org
Mon Feb 15 21:42:34 UTC 2021


valentin.gatienbaron created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The wrapping of `sshpeer.cleanup` silently broke when `cleanup` was
  renamed to `_cleanup`, a couple of years ago.
  
  I don't know what `orig.im_self` is, but regardless, the intention of
  the wrapping seems pretty clear: close stderr before
  sshpeer._cleanuppipes blocks on it. So do that.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/remotefilelog/connectionpool.py

CHANGE DETAILS

diff --git a/hgext/remotefilelog/connectionpool.py b/hgext/remotefilelog/connectionpool.py
--- a/hgext/remotefilelog/connectionpool.py
+++ b/hgext/remotefilelog/connectionpool.py
@@ -43,17 +43,19 @@
 
         if conn is None:
 
-            def _cleanup(orig):
-                # close pipee first so peer.cleanup reading it won't deadlock,
-                # if there are other processes with pipeo open (i.e. us).
-                peer = orig.im_self
-                if util.safehasattr(peer, 'pipee'):
-                    peer.pipee.close()
-                return orig()
+            peer = hg.peer(self._repo.ui, {}, path)
+            if util.safehasattr(peer, '_cleanup'):
 
-            peer = hg.peer(self._repo.ui, {}, path)
-            if util.safehasattr(peer, 'cleanup'):
-                extensions.wrapfunction(peer, b'cleanup', _cleanup)
+                class mypeer(peer.__class__):
+                    def _cleanup(self):
+                        # close pipee first so peer.cleanup reading it won't
+                        # deadlock, if there are other processes with pipeo
+                        # open (i.e. us).
+                        if util.safehasattr(self, 'pipee'):
+                            self.pipee.close()
+                        return super(mypeer, self)._cleanup()
+
+                peer.__class__ = mypeer
 
             conn = connection(pathpool, peer)
 



To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list