Skip to content

Commit a7bfe69

Browse files
roberthoenigtimabbott
authored andcommitted
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.
1 parent 1e8e1f1 commit a7bfe69

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

zulip/zulip/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,15 @@ def do_api_query(self, orig_request, url, method="POST", longpolling=False, file
434434
if files is None:
435435
files = []
436436

437+
if longpolling:
438+
# When long-polling, set timeout to 90 sec as a balance
439+
# between a low traffic rate and a still reasonable latency
440+
# time in case of a connection failure.
441+
request_timeout = 90
442+
else:
443+
# Otherwise, 15s should be plenty of time.
444+
request_timeout = 15
445+
437446
request = {}
438447
req_files = []
439448

@@ -491,10 +500,11 @@ def end_error_retry(succeeded):
491500
if files:
492501
kwargs['files'] = req_files
493502

503+
# Actually make the request!
494504
res = self.session.request(
495505
method,
496506
urllib.parse.urljoin(self.base_url, url),
497-
timeout=90,
507+
timeout=request_timeout,
498508
**kwargs)
499509

500510
# On 50x errors, try again after a short sleep
@@ -547,7 +557,8 @@ def call_endpoint(self, url=None, method="POST", request=None, longpolling=False
547557
# type: (str, str, Dict[str, Any], bool, List[IO]) -> Dict[str, Any]
548558
if request is None:
549559
request = dict()
550-
return self.do_api_query(request, API_VERSTRING + url, method=method, files=files)
560+
return self.do_api_query(request, API_VERSTRING + url, method=method,
561+
longpolling=longpolling, files=files)
551562

552563
def call_on_each_event(self, callback, event_types=None, narrow=None):
553564
# type: (Callable, Optional[List[str]], Any) -> None

0 commit comments

Comments
 (0)