From b9b8178e30f8bf0683dfb4ad1f14ab7e765d9708 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 23 Aug 2019 13:31:17 -0300 Subject: [PATCH] use a semaphore to avoid false timeouts on large syncs --- torba/torba/client/basenetwork.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/torba/torba/client/basenetwork.py b/torba/torba/client/basenetwork.py index da1cf5c70..57d8f901e 100644 --- a/torba/torba/client/basenetwork.py +++ b/torba/torba/client/basenetwork.py @@ -29,6 +29,8 @@ class ClientSession(BaseClientSession): self.pending_amount = 0 self._on_connect_cb = on_connect_callback or (lambda: None) self.trigger_urgent_reconnect = asyncio.Event() + # one request per second of timeout, conservative default + self._semaphore = asyncio.Semaphore(self.timeout) @property def available(self): @@ -54,8 +56,12 @@ class ClientSession(BaseClientSession): return result async def send_request(self, method, args=()): - log.debug("send %s to %s:%i", method, *self.server) self.pending_amount += 1 + async with self._semaphore: + return await self._send_request(method, args) + + async def _send_request(self, method, args=()): + log.debug("send %s to %s:%i", method, *self.server) try: if method == 'server.version': reply = await self.send_timed_server_version_request(args, self.timeout)