D9453: phabricator: use the `http.timeout` config for conduit call

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Sun Nov 29 10:11:15 UTC 2020


marmoute created this revision.
Herald added subscribers: mercurial-patches, Kwan.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Adding some timeout definitely help looping faster through the "bad connection"
  that I suffer from. So lets make it available.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9453

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -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:



To: marmoute, #hg-reviewers
Cc: Kwan, mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list