Skip to content

Commit b28016a

Browse files
committed
request: cache good dns results
1 parent 157a6ea commit b28016a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

boostedblob/request.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ async def raw_execute(self) -> AsyncIterator[aiohttp.ClientResponse]:
4747
)
4848
if config.debug_mode:
4949
print(f"[boostedblob] Making request: {self}", file=sys.stderr)
50-
now = time.time()
50+
now = time.monotonic()
5151
async with ctx as resp:
5252
if config.debug_mode:
53-
duration = time.time() - now
53+
duration = time.monotonic() - now
5454
print(
5555
f"[boostedblob] Completed request, took {duration:.3f}s: {self}",
5656
file=sys.stderr,
@@ -106,7 +106,7 @@ async def execute(self) -> AsyncIterator[aiohttp.ClientResponse]:
106106
jitter_fraction=config.backoff_jitter_fraction,
107107
)
108108
):
109-
now = time.time()
109+
now = time.monotonic()
110110
if (now - last_auth_t) > config.request_reauth_seconds:
111111
if self.auth is not None:
112112
rreq = await self.auth(self)
@@ -130,6 +130,11 @@ async def execute(self) -> AsyncIterator[aiohttp.ClientResponse]:
130130
error = RequestFailure(reason=type(e).__name__ + ": " + str(e), request=self)
131131
else:
132132
if resp.status in self.success_codes:
133+
url = urllib.parse.urlparse(self.url)
134+
hostname = url.hostname
135+
if hostname:
136+
_hostname_check_cache[hostname] = (now + 300, False)
137+
133138
yield resp
134139
return
135140

@@ -377,7 +382,7 @@ async def inner(hostname: str) -> bool:
377382
return True
378383

379384
# maybe this cache is a little bit overkill...
380-
now = time.time()
385+
now = time.monotonic()
381386
if hostname in _hostname_check_cache and _hostname_check_cache[hostname][0] >= now:
382387
return _hostname_check_cache[hostname][1]
383388
ret = await inner(hostname)

0 commit comments

Comments
 (0)