Patchwork [2,of,5] chgserver: invalidate the server if extensions fail to load

login
register
mail settings
Submitter Jun Wu
Date March 14, 2016, 8:33 p.m.
Message ID <e14741b16063879d0d4d.1457987628@x1c>
Download mbox | patch
Permalink /patch/13885/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - March 14, 2016, 8:33 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1457756651 0
#      Sat Mar 12 04:24:11 2016 +0000
# Node ID e14741b16063879d0d4d67a4ad5f0129b8f4f769
# Parent  53123f439567931902cf37c609d275243e9226fe
chgserver: invalidate the server if extensions fail to load

Previously, if extensions fail to load, chg server will just keep working
without those extensions. It will print a warning message but only if a new
server starts.

This patch invalidates the server if any extension failed to load, but still
serve the client (hopefully just) once. It will help chg pass some test cases
of test-bad-extension.t.
Yuya Nishihara - March 15, 2016, 4:04 p.m.
On Mon, 14 Mar 2016 20:33:48 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1457756651 0
> #      Sat Mar 12 04:24:11 2016 +0000
> # Node ID e14741b16063879d0d4d67a4ad5f0129b8f4f769
> # Parent  53123f439567931902cf37c609d275243e9226fe
> chgserver: invalidate the server if extensions fail to load
> 
> Previously, if extensions fail to load, chg server will just keep working
> without those extensions. It will print a warning message but only if a new
> server starts.
> 
> This patch invalidates the server if any extension failed to load, but still
> serve the client (hopefully just) once. It will help chg pass some test cases
> of test-bad-extension.t.

I'm unhappy with this because the server will be spawned per request until bad
extensions are removed from hgrc. But missed warning is also problem. So I would
have to accept this change.

(I'll review the series tomorrow. I was a bit busy today.)

Patch

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -451,7 +451,10 @@ 
         if newhash.mtimehash != self.hashstate.mtimehash:
             addr = _hashaddress(self.baseaddress, self.hashstate.confighash)
             insts.append('unlink %s' % addr)
-            insts.append('reconnect')
+            # mtimehash is empty if one or more extensions fail to load.
+            # to be compatible with hg, still serve the client this time.
+            if self.hashstate.mtimehash:
+                insts.append('reconnect')
         if newhash.confighash != self.hashstate.confighash:
             addr = _hashaddress(self.baseaddress, newhash.confighash)
             insts.append('redirect %s' % addr)
@@ -635,6 +638,7 @@ 
 class chgunixservice(commandserver.unixservice):
     def init(self):
         self._inithashstate()
+        self._checkextensions()
         class cls(AutoExitMixIn, SocketServer.ForkingMixIn,
                   SocketServer.UnixStreamServer):
             ui = self.ui
@@ -647,6 +651,15 @@ 
         self.server.startautoexitthread()
         self._createsymlink()
 
+    def _checkextensions(self):
+        if not self.hashstate:
+            return
+        if extensions.notloaded():
+            # one or more extensions failed to load. mtimehash becomes
+            # meaningless because we do not know the paths of those extensions.
+            # set mtimehash to an illegal hash value to invalidate the server.
+            self.hashstate.mtimehash = ''
+
     def _inithashstate(self):
         self.baseaddress = self.address
         if self.ui.configbool('chgserver', 'skiphash', False):