From 6193936a7ffd61d92234178099b328d833946e19 Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Sat, 12 Mar 2016 04:24:11 +0000 Subject: [PATCH] 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. --- hgext/chgserver.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hgext/chgserver.py b/hgext/chgserver.py index 3ff962e621..3d7e136a7b 100644 --- a/hgext/chgserver.py +++ b/hgext/chgserver.py @@ -451,7 +451,10 @@ class chgcmdserver(commandserver.server): 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) @@ -636,6 +639,7 @@ class AutoExitMixIn: # use old-style to comply with SocketServer design class chgunixservice(commandserver.unixservice): def init(self): self._inithashstate() + self._checkextensions() class cls(AutoExitMixIn, SocketServer.ForkingMixIn, SocketServer.UnixStreamServer): ui = self.ui @@ -656,6 +660,15 @@ class chgunixservice(commandserver.unixservice): self.hashstate = hashstate.fromui(self.ui) self.address = _hashaddress(self.address, self.hashstate.confighash) + 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 _createsymlink(self): if self.baseaddress == self.address: return