Skip to content

Bug: Sync requests.post in async webhook functions blocks event loop #5431

@atlas-agent-omi

Description

@atlas-agent-omi

Problem

backend/utils/webhooks.py has two async def functions that make synchronous requests.post() calls:

  • realtime_transcript_webhook() (line 108) — called on every real-time transcript segment
  • send_audio_bytes_developer_webhook() (line 155) — called for audio byte streaming

These blocking calls stall the entire asyncio event loop while waiting for the external webhook endpoint to respond (up to 15s timeout). During that time, all other concurrent WebSocket connections and async handlers are frozen.

Impact

  • Real-time transcription latency spikes for all users when any single webhook endpoint is slow
  • Audio byte streaming can block the event loop for up to 15 seconds per call
  • Under load with multiple webhook-enabled users, this compounds into cascading stalls

Additionally found 4 more sync-in-async calls in backend/routers/auth.py and backend/routers/oauth.py.

Fix

Wrap sync requests calls with asyncio.to_thread() to offload them to a thread pool, keeping the event loop free:

response = await asyncio.to_thread(
    requests.post, webhook_url, json=payload, headers=headers, timeout=15
)

Files Affected

  • backend/utils/webhooks.py (critical — hot path)
  • backend/routers/auth.py (lower priority — one-time auth flows)
  • backend/routers/oauth.py (lower priority — one-time auth flows)

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend Task (python)bugSomething isn't workingperformance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions