Skip to content

[26.0] Fix event loop blocking in async API routes#22202

Open
mvdbeek wants to merge 1 commit intogalaxyproject:release_26.0from
mvdbeek:fix-async-sync-calls
Open

[26.0] Fix event loop blocking in async API routes#22202
mvdbeek wants to merge 1 commit intogalaxyproject:release_26.0from
mvdbeek:fix-async-sync-calls

Conversation

@mvdbeek
Copy link
Member

@mvdbeek mvdbeek commented Mar 20, 2026

Async def route handlers were calling synchronous DB queries, DNS lookups, and HTTP APIs directly on the event loop, blocking all concurrent requests on the same worker.

  • chat.py: use await agent.run() instead of agent.run_sync(), use AsyncOpenAI instead of sync openai client, wrap all chat_manager and job_manager DB calls with anyio.to_thread.run_sync
  • agents.py: wrap chat_manager/job_manager DB calls in analyze_error and create_custom_tool with anyio.to_thread.run_sync
  • proxy.py: wrap _validate_url_and_access (blocking socket.getaddrinfo) with anyio.to_thread.run_sync
  • error_analysis.py: wrap job_manager.get_accessible_job with anyio.to_thread.run_sync

How to test the changes?

(Select all options that apply)

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

Async def route handlers were calling synchronous DB queries, DNS
lookups, and HTTP APIs directly on the event loop, blocking all
concurrent requests on the same worker.

- chat.py: use await agent.run() instead of agent.run_sync(), use
  AsyncOpenAI instead of sync openai client, wrap all chat_manager
  and job_manager DB calls with anyio.to_thread.run_sync
- agents.py: wrap chat_manager/job_manager DB calls in analyze_error
  and create_custom_tool with anyio.to_thread.run_sync
- proxy.py: wrap _validate_url_and_access (blocking socket.getaddrinfo)
  with anyio.to_thread.run_sync
- error_analysis.py: wrap job_manager.get_accessible_job with
  anyio.to_thread.run_sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

1 participant