diff mercurial/keepalive.py @ 40043:6509fcec830c

url: allow to configure timeout on http connection By default, httplib.HTTPConnection opens connection with no timeout. If the server is hanging, Mercurial will wait indefinitely. This may be an issue for automated scripts. Differential Revision: https://phab.mercurial-scm.org/D4878
author Cédric Krier <ced@b2ck.com>
date Thu, 04 Oct 2018 11:28:48 +0200
parents 5e5b06087ec5
children 41506e3b04ee
line wrap: on
line diff
--- a/mercurial/keepalive.py	Wed Sep 26 23:50:14 2018 +0200
+++ b/mercurial/keepalive.py	Thu Oct 04 11:28:48 2018 +0200
@@ -172,8 +172,9 @@
             return dict(self._hostmap)
 
 class KeepAliveHandler(object):
-    def __init__(self):
+    def __init__(self, timeout=None):
         self._cm = ConnectionManager()
+        self._timeout = timeout
         self.requestscount = 0
         self.sentbytescount = 0
 
@@ -234,7 +235,7 @@
                 h = self._cm.get_ready_conn(host)
             else:
                 # no (working) free connections were found.  Create a new one.
-                h = http_class(host)
+                h = http_class(host, timeout=self._timeout)
                 if DEBUG:
                     DEBUG.info("creating new connection to %s (%d)",
                                host, id(h))