From 5286e26cc346c9abef57eed7c3f1c447938377eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20K=C3=B6lling?= Date: Fri, 11 Mar 2022 22:46:53 +0100 Subject: [PATCH] async: schedule next request earlier to actually delay async requests --- ipfsspec/async_ipfs.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ipfsspec/async_ipfs.py b/ipfsspec/async_ipfs.py index 38b4f2e..ef1cbe6 100644 --- a/ipfsspec/async_ipfs.py +++ b/ipfsspec/async_ipfs.py @@ -188,11 +188,14 @@ def _gws_in_priority_order(self): async def _gw_op(self, op): for _ in range(self.max_backoff_rounds): for state, gw in self._gws_in_priority_order: + not_before = state.next_request_time if not state.reachable: state.trying_to_reach() + else: + state.schedule_next() now = time.monotonic() - if state.next_request_time > now: - await asyncio.sleep(state.next_request_time - now) + if not_before > now: + await asyncio.sleep(not_before - now) logger.debug("tring %s", gw) try: res = await op(gw)