From a7bfe692fa4ce596397168bc807ef83b1ede5b18 Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Fri, 6 Oct 2017 17:00:41 +0200 Subject: [PATCH] api: Fix unused long-polling retry parameter. This parameter was intended to control whether we give a long timeout and related behavior, but it was accidentally not being passed into the second layer of the library from the first. While we're fixing it, make it actually limit the length of a timeout to something reasonable. --- zulip/zulip/__init__.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 5d3e3cb..17f7724 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -434,6 +434,15 @@ class Client(object): if files is None: files = [] + if longpolling: + # When long-polling, set timeout to 90 sec as a balance + # between a low traffic rate and a still reasonable latency + # time in case of a connection failure. + request_timeout = 90 + else: + # Otherwise, 15s should be plenty of time. + request_timeout = 15 + request = {} req_files = [] @@ -491,10 +500,11 @@ class Client(object): if files: kwargs['files'] = req_files + # Actually make the request! res = self.session.request( method, urllib.parse.urljoin(self.base_url, url), - timeout=90, + timeout=request_timeout, **kwargs) # On 50x errors, try again after a short sleep @@ -547,7 +557,8 @@ class Client(object): # type: (str, str, Dict[str, Any], bool, List[IO]) -> Dict[str, Any] if request is None: request = dict() - return self.do_api_query(request, API_VERSTRING + url, method=method, files=files) + return self.do_api_query(request, API_VERSTRING + url, method=method, + longpolling=longpolling, files=files) def call_on_each_event(self, callback, event_types=None, narrow=None): # type: (Callable, Optional[List[str]], Any) -> None