Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _fetch_pubkey(self):
break
except ValueError as e:
log.debug(f"Error downloading key: {e}")
time.sleep(15)
await sleep(15)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_fetch_pubkey is not guaranteed to be only called in an async context; we should mark it (and its whole calling chain) async if it needs to be called in an async context.

if key is None:
self._total_pubkey_fetch_errors += 1
if self._total_pubkey_fetch_errors >= MAX_PUBKEY_FETCH_ATTEMPTS:
Expand Down Expand Up @@ -138,9 +138,12 @@ async def cancel_api_call_if_disconnected() -> web.Response:
async def make_request() -> Union[web.Response, web.StreamResponse]:
log.debug(f"got request, {auth_data.reqnum}")
self.metrics._request_start(workload=workload, reqnum=auth_data.reqnum)

acquired = False
if self.allow_parallel_requests is False:
log.debug(f"Waiting to aquire Sem for reqnum:{auth_data.reqnum}")
await self.sem.acquire()
acquired = True
log.debug(
f"Sem acquired for reqnum:{auth_data.reqnum}, starting request..."
)
Expand All @@ -160,7 +163,7 @@ async def make_request() -> Union[web.Response, web.StreamResponse]:
res = await handler.generate_client_response(request, response)
self.metrics._request_success(workload=workload)
return res
except requests.exceptions.RequestException as e:
except aiohttp.ClientError as e:
log.debug(f"[backend] Request error: {e}")
self.metrics._request_errored(workload=workload)
return web.Response(status=500)
Expand All @@ -169,7 +172,8 @@ async def make_request() -> Union[web.Response, web.StreamResponse]:
workload=workload,
reqnum=auth_data.reqnum,
)
self.sem.release()
if acquired:
self.sem.release()

###########

Expand Down Expand Up @@ -387,7 +391,7 @@ async def tail_log():
if line:
await handle_log_line(line.rstrip())
else:
time.sleep(LOG_POLL_INTERVAL)
await sleep(LOG_POLL_INTERVAL)

###########

Expand Down