comparison hgext/phabricator.py @ 45970:4d70444c3ea9

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
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 29 Nov 2020 00:05:50 +0100
parents 57183111a463
children 9624bf057c2a
comparison
equal deleted inserted replaced
45969:57183111a463 45970:4d70444c3ea9
40 # 40 #
41 # We wait `retry.interval` between each retry, in seconds. 41 # We wait `retry.interval` between each retry, in seconds.
42 # (default 1 second). 42 # (default 1 second).
43 retry = 3 43 retry = 3
44 retry.interval = 10 44 retry.interval = 10
45
46 # the retry option can combine well with the http.timeout one.
47 #
48 # For example to give up on http request after 20 seconds:
49 [http]
50 timeout=20
45 51
46 [auth] 52 [auth]
47 example.schemes = https 53 example.schemes = https
48 example.prefix = phab.example.com 54 example.prefix = phab.example.com
49 55
418 body = sout.read() 424 body = sout.read()
419 else: 425 else:
420 urlopener = urlmod.opener(ui, authinfo) 426 urlopener = urlmod.opener(ui, authinfo)
421 request = util.urlreq.request(pycompat.strurl(url), data=data) 427 request = util.urlreq.request(pycompat.strurl(url), data=data)
422 max_try = ui.configint(b'phabricator', b'retry') + 1 428 max_try = ui.configint(b'phabricator', b'retry') + 1
429 timeout = ui.configwith(float, b'http', b'timeout')
423 for try_count in range(max_try): 430 for try_count in range(max_try):
424 try: 431 try:
425 with contextlib.closing(urlopener.open(request)) as rsp: 432 with contextlib.closing(
433 urlopener.open(request, timeout=timeout)
434 ) as rsp:
426 body = rsp.read() 435 body = rsp.read()
427 break 436 break
428 except util.urlerr.urlerror as err: 437 except util.urlerr.urlerror as err:
429 if try_count == max_try - 1: 438 if try_count == max_try - 1:
430 raise 439 raise