From 4cec3b1c4a84f192020d8a862fb46767c6482198 Mon Sep 17 00:00:00 2001 From: Maciej Pytel Date: Fri, 17 Apr 2015 10:14:02 +0000 Subject: [PATCH 1/3] Disable urllib3 retry when timeout is explicitly specified. This is to fix #81. --- src/etcd/client.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/etcd/client.py b/src/etcd/client.py index 516e335e..86e602ad 100644 --- a/src/etcd/client.py +++ b/src/etcd/client.py @@ -543,12 +543,15 @@ def api_execute(self, path, method, params=None, timeout=None): some_request_failed = False response = False + request_kwargs = {} if timeout is None: timeout = self.read_timeout + else: + request_kwargs['retries'] = False - if timeout == 0: - timeout = None + if timeout: + request_kwargs['timeout'] = timeout if not path.startswith('/'): raise ValueError('Path does not start with /') @@ -561,23 +564,24 @@ def api_execute(self, path, method, params=None, timeout=None): response = self.http.request( method, url, - timeout=timeout, fields=params, - redirect=self.allow_redirect) + redirect=self.allow_redirect, + **request_kwargs) elif (method == self._MPUT) or (method == self._MPOST): response = self.http.request_encode_body( method, url, fields=params, - timeout=timeout, encode_multipart=False, - redirect=self.allow_redirect) + redirect=self.allow_redirect, + **request_kwargs) else: raise etcd.EtcdException( 'HTTP method {} not supported'.format(method)) - except urllib3.exceptions.MaxRetryError: + except (urllib3.exceptions.MaxRetryError, + urllib3.exceptions.ProtocolError): self._base_uri = self._next_server() some_request_failed = True From b164c942cc18319e0bdd5bde28a48cc32de21c88 Mon Sep 17 00:00:00 2001 From: Maciej Pytel Date: Fri, 17 Apr 2015 10:43:04 +0000 Subject: [PATCH 2/3] Using ConnectionError for compatibility with urllib3. --- src/etcd/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etcd/client.py b/src/etcd/client.py index 86e602ad..793a7285 100644 --- a/src/etcd/client.py +++ b/src/etcd/client.py @@ -581,7 +581,7 @@ def api_execute(self, path, method, params=None, timeout=None): 'HTTP method {} not supported'.format(method)) except (urllib3.exceptions.MaxRetryError, - urllib3.exceptions.ProtocolError): + urllib3.exceptions.ConnectionError): self._base_uri = self._next_server() some_request_failed = True From 21c76a65e973380811cf9c5d0111add7f3d2c4a0 Mon Sep 17 00:00:00 2001 From: Maciej Pytel Date: Fri, 17 Apr 2015 11:15:51 +0000 Subject: [PATCH 3/3] Different checking for non-timeout errors. This is to support very old urllib3 versions. --- src/etcd/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/etcd/client.py b/src/etcd/client.py index 793a7285..f0aa5d7b 100644 --- a/src/etcd/client.py +++ b/src/etcd/client.py @@ -580,8 +580,10 @@ def api_execute(self, path, method, params=None, timeout=None): raise etcd.EtcdException( 'HTTP method {} not supported'.format(method)) - except (urllib3.exceptions.MaxRetryError, - urllib3.exceptions.ConnectionError): + except urllib3.exceptions.HTTPError as exc: + if 'timeout' in request_kwargs and \ + isinstance(exc, urllib3.exceptions.TimeoutError): + raise self._base_uri = self._next_server() some_request_failed = True