Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions backend/routers/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import os
import uuid
import json
Expand Down Expand Up @@ -283,7 +284,7 @@ async def _exchange_google_code_for_oauth_credentials(code: str, session_data: d
'grant_type': 'authorization_code',
}

token_response = requests.post(token_url, data=token_data)
token_response = await asyncio.to_thread(requests.post, token_url, data=token_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

The three requests.post calls converted to asyncio.to_thread in this file (Google token exchange, Apple token exchange, and Firebase sign-in) lack timeout parameters. While these calls no longer block the event loop directly, they still consume thread-pool slots. Without a timeout, a slow or unresponsive endpoint could hang indefinitely. Consider adding a reasonable timeout (e.g., timeout=10) to match the pattern already established in webhooks.py:

Suggested change
token_response = await asyncio.to_thread(requests.post, token_url, data=token_data)
token_response = await asyncio.to_thread(requests.post, token_url, data=token_data, timeout=10)

The same applies to the Apple token exchange at line 344 and Firebase sign-in at line 412.

if token_response.status_code != 200:
raise HTTPException(status_code=400, detail="Failed to exchange Google code")

Expand Down Expand Up @@ -340,7 +341,8 @@ async def _exchange_apple_code_for_oauth_credentials(code: str, session_data: di
'redirect_uri': callback_url,
}

token_response = requests.post(
token_response = await asyncio.to_thread(
requests.post,
token_url, data=token_data, headers={'Content-Type': 'application/x-www-form-urlencoded'}
)

Expand Down Expand Up @@ -407,7 +409,7 @@ async def _generate_custom_token(provider: str, id_token: str, access_token: str
}

# Call Firebase Auth REST API to sign in
response = requests.post(sign_in_url, json=payload)
response = await asyncio.to_thread(requests.post, sign_in_url, json=payload)

if response.status_code != 200:
logger.error(f"Firebase sign-in failed: {sanitize(response.text)}")
Expand Down
3 changes: 2 additions & 1 deletion backend/routers/oauth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import os
from typing import Optional
from fastapi import APIRouter, Request, HTTPException, Form
Expand Down Expand Up @@ -139,7 +140,7 @@ async def oauth_token(firebase_id_token: str = Form(...), app_id: str = Form(...
# Check Setup completes
if app.works_externally() and app.external_integration.setup_completed_url:
try:
res = requests.get(app.external_integration.setup_completed_url + f'?uid={uid}')
res = await asyncio.to_thread(requests.get, app.external_integration.setup_completed_url + f'?uid={uid}')
res.raise_for_status()
if not res.json().get('is_setup_completed', False):
raise HTTPException(
Expand Down
6 changes: 4 additions & 2 deletions backend/utils/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ async def realtime_transcript_webhook(uid, segments: List[dict]):
return
webhook_url += f'?uid={uid}'
try:
response = requests.post(
response = await asyncio.to_thread(
requests.post,
webhook_url,
json={'segments': segments, 'session_id': uid},
headers={'Content-Type': 'application/json'},
Expand Down Expand Up @@ -163,7 +164,8 @@ async def send_audio_bytes_developer_webhook(uid: str, sample_rate: int, data: b
return
webhook_url += f'?sample_rate={sample_rate}&uid={uid}'
try:
response = requests.post(
response = await asyncio.to_thread(
requests.post,
webhook_url, data=data, headers={'Content-Type': 'application/octet-stream'}, timeout=15
)
logger.info(f'send_audio_bytes_developer_webhook: {webhook_url} {response.status_code}')
Expand Down