Mercurial > hg
changeset 34064:8b659b7388c0
phabricator: add a config to use curl for communication
Not sure why, but I got `phabsend` hang on work network pretty frequently.
The traceback indicates it hangs at `_sslobj.do_handshake()`:
File "mercurial/sslutil.py", line 404, in wrapsocket
sslsocket = sslcontext.wrap_socket(sock, server_hostname=serverhostname)
File "/usr/lib/python2.7/ssl.py", line 363, in wrap_socket
_context=self)
File "/usr/lib/python2.7/ssl.py", line 611, in __init__
self.do_handshake()
File "/usr/lib/python2.7/ssl.py", line 840, in do_handshake
self._sslobj.do_handshake()
I had tried adding `timeout` in various places but they seem not effective.
It seems easier to just allow shelling out to `curl` with retry and timeout
flags.
This could also be helpful for people with an older Python installed without
modern security (SNI).
Differential Revision: https://phab.mercurial-scm.org/D605
author | Jun Wu <quark@fb.com> |
---|---|
date | Fri, 01 Sep 2017 12:13:17 -0700 |
parents | 941c33cfde81 |
children | c6c8a52e28c9 |
files | contrib/phabricator.py |
diffstat | 1 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/phabricator.py Thu Aug 24 18:00:23 2017 -0700 +++ b/contrib/phabricator.py Fri Sep 01 12:13:17 2017 -0700 @@ -28,6 +28,11 @@ # callsign is "FOO". callsign = FOO + # curl command to use. If not set (default), use builtin HTTP library to + # communicate. If set, use the specified curl command. This could be useful + # if you need to specify advanced options that is not easily supported by + # the internal library. + curlcmd = curl --connect-timeout 2 --retry 3 --silent """ from __future__ import absolute_import @@ -108,12 +113,20 @@ """call Conduit API, params is a dict. return json.loads result, or None""" host, token = readurltoken(repo) url, authinfo = util.url('/'.join([host, 'api', name])).authinfo() - urlopener = urlmod.opener(repo.ui, authinfo) repo.ui.debug('Conduit Call: %s %s\n' % (url, params)) params = params.copy() params['api.token'] = token - request = util.urlreq.request(url, data=urlencodenested(params)) - body = urlopener.open(request).read() + data = urlencodenested(params) + curlcmd = repo.ui.config('phabricator', 'curlcmd') + if curlcmd: + sin, sout = util.popen2('%s -d @- %s' % (curlcmd, util.shellquote(url))) + sin.write(data) + sin.close() + body = sout.read() + else: + urlopener = urlmod.opener(repo.ui, authinfo) + request = util.urlreq.request(url, data=data) + body = urlopener.open(request).read() repo.ui.debug('Conduit Response: %s\n' % body) parsed = json.loads(body) if parsed.get(r'error_code'):