Repository navigation
Open
Milestone
Description
Body
Context
- An
async defFastAPI dependency that runs a sync query waits for a pooled connection on the event loop. When the pool is full, the loop blocks, and the requests holding connections can't release them, because their teardown needs the loop too. That stalled 3.4.0rc2 under concurrent writes (API server stalls under concurrent write requests in 3.4.0rc2 #76417, found in Status of testing of Apache Airflow 3.4.0rc3 #75865 (comment)). - Keep the audit log off the API server event loop #76416 fixes the 3.4.0 regression in
log_action. Fail API tests that run sync DB work on the event loop #76424 adds tests that fail on sync DB work on the event loop, with the known offenders listed as strict xfails ingenerated/. - The items below are the same pattern. They were already in 3.3.2 and are off the common path, so they are 3.4.1 follow-ups, not RC blockers. Under load each one still wedges the whole server: a single call per second is enough once the pool is busy.
Follow-up items
-
requires_access_backfillincore_api/security.py: looks upBackfill.dag_idon/backfills/{backfill_id}and its/dag_runs,/pause,/unpauseand/cancelroutes.DagModel.get_team_namealso runs on the loop when its cache misses. -
requires_access_event_logincore_api/security.py: looks up theLogrow onGET /eventLogs/{event_log_id}. -
_collect_teams_to_checkincore_api/security.py(only with[core] multi_team = True): calls the syncPool,ConnectionorVariableget_team_nameon detail, update and delete routes. It also callsTeam.get_name_if_existswhen a create or update body setsteam_name. -
BaseAuthManager.get_user_from_token: replacerun_in_threadpool(RevokedToken.is_revoked, ...)with an async query. It's listed ingenerated/known_api_server_threadpool_offloads.txt. -
GET /api/v2/dags:get_dagspasses the lazysession.scalars(...)intoIterable[DAGResponse], so the rows and thedag_tagquery are read while FastAPI serializes the response on the loop. Materialize it with.all(), and check the other list routes whose collection field isIterable[...]. 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_userruns a sync user query fromget_user_from_tokenon 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 theGET /dagscase), are not covered. The mounted/executionapp isn't covered either, because the sweep's UI token is rejected there before any route dependency runs.
How to fix
- Run the lookup on the async engine instead of the sync session. Take
AsyncSessionDep, or useasync with create_session_async() as session:, andawait session.scalar(...), as Keep the audit log off the API server event loop #76416 does forlog_action. Add async variants of the sync@provide_sessionhelpers where needed. Don't wrap the call inrun_in_threadpool:TestNoThreadpoolOffloadfails on any new offload. - Delete the fixed routes' lines from
generated/known_sync_db_on_event_loop.txt, or fromgenerated/known_api_server_threadpool_offloads.txtforis_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
xchwan commentedon Nov 4, 2026
@jason810496 I'll take "requires_access_event_log in core_api/security.py: looks up the Log row on GET /eventLogs/{event_log_id}."
aaron-y-chen commentedon Nov 4, 2026
I'll take
requires_access_backfill, thank you!Andrushika commentedon Nov 5, 2026
I'll pick up
_collect_teams_to_checkone, thanks!ccoliu commentedon Nov 5, 2026
I'll take the GET /api/v2/dags item, including checking the other list routes whose collection field is Iterable[...]. Thanks!
kevinhongzl commentedon Nov 5, 2026
I'll work on the
BaseAuthManager.get_user_from_tokenone.fat-catTW commentedon Nov 9, 2026
I'll work on FAB provider.
Thanks