phabricator: use the `http.timeout` config for conduit call
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 29 Nov 2020 00:05:50 +0100
changeset 45970 4d70444c3ea9
parent 45969 57183111a463
child 45971 cc759d3db1e8
phabricator: use the `http.timeout` config for conduit call Adding some timeout definitely help looping faster through the "bad connection" that I suffer from. So lets make it available. Differential Revision: https://phab.mercurial-scm.org/D9453
hgext/phabricator.py
--- a/hgext/phabricator.py	Sat Nov 28 19:58:37 2020 +0100
+++ b/hgext/phabricator.py	Sun Nov 29 00:05:50 2020 +0100
@@ -43,6 +43,12 @@
     retry = 3
     retry.interval = 10
 
+    # the retry option can combine well with the http.timeout one.
+    #
+    # For example to give up on http request after 20 seconds:
+    [http]
+    timeout=20
+
     [auth]
     example.schemes = https
     example.prefix = phab.example.com
@@ -420,9 +426,12 @@
         urlopener = urlmod.opener(ui, authinfo)
         request = util.urlreq.request(pycompat.strurl(url), data=data)
         max_try = ui.configint(b'phabricator', b'retry') + 1
+        timeout = ui.configwith(float, b'http', b'timeout')
         for try_count in range(max_try):
             try:
-                with contextlib.closing(urlopener.open(request)) as rsp:
+                with contextlib.closing(
+                    urlopener.open(request, timeout=timeout)
+                ) as rsp:
                     body = rsp.read()
                 break
             except util.urlerr.urlerror as err: