Skip to content

Move the remaining sync DB lookups off the API server event loop #76425

Open

Description

@jason810496

Body

Context

Follow-up items

  • requires_access_backfill in core_api/security.py: looks up Backfill.dag_id on /backfills/{backfill_id} and its /dag_runs, /pause, /unpause and /cancel routes. DagModel.get_team_name also runs on the loop when its cache misses.
  • requires_access_event_log in core_api/security.py: looks up the Log row on GET /eventLogs/{event_log_id}.
  • _collect_teams_to_check in core_api/security.py (only with [core] multi_team = True): calls the sync Pool, Connection or Variable get_team_name on detail, update and delete routes. It also calls Team.get_name_if_exists when a create or update body sets team_name.
  • BaseAuthManager.get_user_from_token: replace run_in_threadpool(RevokedToken.is_revoked, ...) with an async query. It's listed in generated/known_api_server_threadpool_offloads.txt.
  • GET /api/v2/dags: get_dags passes the lazy session.scalars(...) into Iterable[DAGResponse], so the rows and the dag_tag query are read while FastAPI serializes the response on the loop. Materialize it with .all(), and check the other list routes whose collection field is Iterable[...]. Keep get_dag_details and get_pools database queries off the API server event loop #74247 fixed the same shape for Dag details and pools.
  • FAB provider: FabAuthManager.deserialize_user runs a sync user query from get_user_from_token on the loop each time its per-user cache ([fab] cache_ttl) expires.
  • Coverage (test_event_loop_blocking.py): the sweep sends "1" for every path parameter and {} as the body against an empty DB. Routes that reject that input early, or that only query when rows exist (such as the GET /dags case), are not covered. The mounted /execution app isn't covered either, because the sweep's UI token is rejected there before any route dependency runs.

How to fix

  1. Run the lookup on the async engine instead of the sync session. Take AsyncSessionDep, or use async with create_session_async() as session:, and await session.scalar(...), as Keep the audit log off the API server event loop #76416 does for log_action. Add async variants of the sync @provide_session helpers where needed. Don't wrap the call in run_in_threadpool: TestNoThreadpoolOffload fails on any new offload.
  2. Delete the fixed routes' lines from generated/known_sync_db_on_event_loop.txt, or from generated/known_api_server_threadpool_offloads.txt for is_revoked. Each line is a strict xfail, so the run fails until the line is removed.

Committer

  • I acknowledge that I am a maintainer/committer of the Apache Airflow project.

Activity

  1. self-assigned this
    on Nov 4, 2026
  2. added
    kind:meta
    area:API
    on Nov 4, 2026
  3. added this to the Airflow 3.4.1 milestone on Nov 4, 2026
  4. xchwan commented on Nov 4, 2026

    @xchwan
    Contributor

    @jason810496 I'll take "requires_access_event_log in core_api/security.py: looks up the Log row on GET /eventLogs/{event_log_id}."

  5. aaron-y-chen commented on Nov 4, 2026

    @aaron-y-chen
    Contributor

    I'll takerequires_access_backfill, thank you!

  6. Andrushika commented on Nov 5, 2026

    @Andrushika
    Contributor

    I'll pick up _collect_teams_to_check one, thanks!

  7. ccoliu commented on Nov 5, 2026

    @ccoliu
    Contributor

    I'll take the GET /api/v2/dags item, including checking the other list routes whose collection field is Iterable[...]. Thanks!

  8. kevinhongzl commented on Nov 5, 2026

    @kevinhongzl
    Contributor

    I'll work on the BaseAuthManager.get_user_from_token one.

  9. fat-catTW commented on Nov 9, 2026

    @fat-catTW
    Contributor

    I'll work on FAB provider.
    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:APIkind:meta

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions