Patchwork D9997: remotefilelog: rework workaround for sshpeer deadlocks

login
register
mail settings
Submitter phabricator
Date Feb. 15, 2021, 9:42 p.m.
Message ID <differential-rev-PHID-DREV-bpc7ghgaestvir5mnw3d-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48311/
State New
Headers show

Comments

phabricator - Feb. 15, 2021, 9:42 p.m.
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




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

Patch

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)