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

login
register
mail settings
Submitter phabricator
Date Nov. 29, 2020, 10:11 a.m.
Message ID <differential-rev-PHID-DREV-qk4jffhvvs3pm4ty5mkj-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47732/
State Superseded
Headers show

Comments

phabricator - Nov. 29, 2020, 10:11 a.m.
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




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

Patch

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: