Patchwork [3,of,3,hglib] hgclient: look for an open server before closing it in ResponseError block

login
register
mail settings
Submitter Augie Fackler
Date Dec. 10, 2017, 5:54 p.m.
Message ID <20fdbd5e5d426bb710df.1512928494@imladris.local>
Download mbox | patch
Permalink /patch/26200/
State Accepted
Headers show

Comments

Augie Fackler - Dec. 10, 2017, 5:54 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1512928357 18000
#      Sun Dec 10 12:52:37 2017 -0500
# Node ID 20fdbd5e5d426bb710df2be46b7877ea99d18ada
# Parent  a58ab92c962337fe177001ec17df0efc673e8279
hgclient: look for an open server before closing it in ResponseError block

At least some of the codepaths that can throw a ResponseError close
the server first (the one in _readchannel does so in order to detect
server startup failures, for example), so we have to verify we have a
server to close before doing so, otherwise we can lose the
ResponseError and the user sees an AttributeError when we try to use
.close() on a NoneType.

Patch

diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -271,7 +271,8 @@  class hgclient(object):
         try:
             self._readhello()
         except error.ResponseError:
-            self.close()
+            if self.server is not None:
+                self._close()
             raise
         except error.ServerError:
             if self.server is None: