Skip to content

Fix: use httpx.AsyncClient in async FastAPI handlers to prevent event loop blocking #559

Description

@selena731

Replace httpx.Client with httpx.AsyncClient in the listed async FastAPI handlers to avoid blocking the uvicorn event loop. Update code and add tests validating endpoints remain responsive under long-running operations.

Affected files/handlers (from parent issue #219):

  • server/routes.py: POST /v1/models/pull (server/routes.py:487)
  • server/routes.py: DELETE /v1/models/{name} (server/routes.py:518)
  • server/api_routes.py: POST /v1/speech/transcribe (server/api_routes.py:685)
  • server/agent_manager_routes.py: SendBlue verify/register/test (lines ~1775,1839,1890)

Implementation notes:

  • Use async with httpx.AsyncClient(...) and await client.post/get
  • For CPU-bound tasks (e.g., Whisper), offload with asyncio.to_thread
  • Add unit/integration tests that mock remote endpoints and simulate long-duration calls

Metadata

Metadata

Assignees

Type

Fields

Priority

P0

Effort

M

Projects

Status
In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions