Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
affected_version:3.2Use for reporting issues with 3.2area:MetaDBMeta Database related issues.area:corearea:performancekind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yetpending-responsepriority:highHigh priority bug that should be patched quickly but does not require immediate new releasestaleStale PRs per the .github/workflows/stale.yml policy file
Description
Under which category would you file this issue?
Providers
Apache Airflow version
3.2.1
What happened and how to reproduce it?
When have tens of tasks in-flight, and while surfing the UI, occasionally we get
- Queued up hertbeat UPDATE queries in the airflow api
- Connection pool exhaustion
- API response times to the heartbeats is high, causing workers to timeout, and retry.
- Some tasks terminated and put into a retry state
What you think should happen instead?
No response
Operating System
No response
Deployment
Other Docker-based deployment
Apache Airflow Provider(s)
celery
Versions of Apache Airflow Providers
No response
Official Helm Chart version
Not Applicable
Kubernetes Version
No response
Helm Chart configuration
No response
Docker Image customizations
No response
Anything else?
Some query prevents the heartbeat UPDATEs
usename state xact_duration query_duration query
db_user idle in transaction 00:00:22.17721 00:00:00.06658 SELECT task_instance.state AS task_instance_state
FROM task_instance
WHERE task_instance.id = '0<zzzyyy>54'::uuid::UUID
db_user active 00:00:22.123495 00:00:22.120761 UPDATE task_instance SET last_heartbeat_at='2026-04-23T09:03:18.258390+00:00'::timestamptz, updated_at='2026-04-23T09:03:18.261693+00:00'::timestamptz WHERE task_instance.id
db_user active 00:00:22.058237 00:00:22.054038 UPDATE task_instance SET last_heartbeat_at='2026-04-23T09:03:18.320462+00:00'::timestamptz, updated_at='2026-04-23T09:03:18.324080+00:00'::timestamptz WHERE task_instance.id
db_user active 00:00:21.901896 00:00:21.89822 UPDATE task_instance SET last_heartbeat_at='2026-04-23T09:03:18.479643+00:00'::timestamptz, updated_at='2026-04-23T09:03:18.483318+00:00'::timestamptz WHERE task_instance.id
db_user active 00:00:21.537818 00:00:21.534485 UPDATE task_instance SET last_heartbeat_at='2026-04-23T09:03:18.844164+00:00'::timestamptz, updated_at='2026-04-23T09:03:18.847447+00:00'::timestamptz WHERE task_instance.id
...
Slow endpoints
| # | Duration (s) | Status | Method | Endpoint |
|---|---|---|---|---|
| 1 | 72.02 | 200 | GET | /api/v2/dags/XYZ/dagRuns/~/hitlDetails?state=deferred&response_received=false |
| 2 | 71.88 | 200 | GET | /ui/grid/runs/QAZ?limit=25&order_by=-run_after |
| 3 | 71.05 | 204 | PATCH | /execution/task-instances/ZAQ/state |
| 4 | 71.01 | 200 | GET | /api/v2/dags/QWE/details |
| 5 | 70.91 | 200 | GET | /ui/dags/EWQ/latest_run |
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Reacted by Amit Jha, mariusz-zalewski-vetology and Marko Petzold
Metadata
Metadata
Assignees
Labels
affected_version:3.2Use for reporting issues with 3.2area:MetaDBMeta Database related issues.area:corearea:performancekind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yetpending-responsepriority:highHigh priority bug that should be patched quickly but does not require immediate new releasestaleStale PRs per the .github/workflows/stale.yml policy file
Activity
boring-cyborg commentedon Apr 23, 2026
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
Subham-KRLX commentedon Apr 23, 2026
Confirmed this is a mix of connection pool exhaustion from streaming endpoints and lock contention in the TI update path I have found a few spots where transactions are held open unnecessarily blocking heartbeats I am currently putting together a PR to decouple these sessions and optimize the hot paths.
jscheffl commentedon Apr 23, 2026
We had the same in Airflow 3.1.5 and mainly at that time it was caused by slow scheduler queries blocking the task_instance table also blocking heartbeat calls.
Can you double check this is related to UI streaming calls or might be (still?) related to locks by scheduler? In our case it helped to set
scheduler_health_check_threshold: 3000in the configs (helm chart).serhii-karelov commentedon Apr 24, 2026
I can see that the issue persists even when no any API requests from UI.
Also I tried to see whether there are any slow API calls (10sec or more) except of heartbeats (that are slow because they are locked), and I can see only occasional
method=PATCH path=/execution/task-instances/xxxx/state query=. So it doesn't look like there is a particular API endpoint that locks task instances.Happy to provide more information if needed.
mdw00d commentedon May 5, 2026
Not sure if this is related but we are experiencing what may be a similar issue where we have lots of tasks accumulating in the "idle in transaction" state executing a query of the form:
Not sure where this query is originating; perhaps someone more knowledgeable would know where?
This eventually causes an unrecoverable error situation.
sdg9670f commentedon May 7, 2026
Same here. I couldn't identify a slow query, but it seems some are being delayed by locks.
shivaam commentedon May 21, 2026
Looks like this may be fixed by #67246, which landed yesterday and will be in 3.2.2. The slow
PATCH /stateyou flagged matches what that PR addresses.@avolant — does this look related to what you were fixing?
@serhii-karelov — would you be able to retest once 3.2.2 is out?
2 remaining items
Gourigupta2004 commentedon Jun 28, 2026
Hi @serhii-karelov,
I would like investigate and work on this issue. Please assign this to me
potiuk commentedon Jun 29, 2026
We do not assign issues (see contributing guides) - but feel free to work on it.
SamWheating commentedon Jul 1, 2026
It seems like we're seeing the same issue running in 3.2.2 at large scale - seeing lots of idle in transaction queries like this:
which then exhaust pgbouncer's pool and eventually cause api-servers, schedulers etc to fail.
I'll continue to investigate and share updates here, but I don't think that this was fixed by the linked PR.
seanmuth commentedon Jul 13, 2026
Confirming this is still present on 3.2.2 (i.e. with #67246 already applied), at scale.
Adding a concrete reproduction from a large on-prem deployment in case the numbers help narrow the hot path.
Environment
Symptom
Sessions pile up in
idle in transactionwhile still holdingtask_instancerow locks, and the count grows over time until PgBouncer's pool is exhausted and the api-servers/schedulers restart. The blocking chains are dominated by two query shapes:Correlated endpoint latencies (captured while clearing tasks on the ~350-task DAG and browsing the grid concurrently):
POST .../clearTaskInstancesPOST .../clearTaskInstancesGET /ui/grid/structure/<large_dag>(limit=10)Trigger: clearing a large task group while the grid UI is being polled for the same DAG. The idle-in-transaction sessions holding
task_instancelocks block the heartbeatUPDATEs, workers then time out heartbeating and retry/terminate, and the scheduler stalls on the same table — consistent with the cascade described in the issue.Interim mitigation we're validating (not a fix): scoping a tighter
idle_in_transaction_session_timeouton the Airflow DB role to forcibly release the leaked locks and keep the pool from exhausting. It stops the api-server restarts but obviously doesn't address the sessions being held open across slow work in the first place.Happy to pull more detail (full
pg_stat_activitysnapshots withwait_event/state, blocking-PID chains) if useful.🤖 Generated with Claude Code — Claude Opus 4.8 (1M context)
github-actions commentedon Jul 29, 2026
This issue has been automatically marked as stale because it has been open for 14 days with no response from the author. It will be closed in next 7 days if no further activity occurs from the issue author.
github-actions commentedon Aug 5, 2026
This issue has been closed because it has not received response from the issue author.
Release DB connection before deserializing DAGs in grid structure end…
Release DB connection before deserializing DAGs in grid structure end…
[v3-3-test] Release DB connection before deserializing DAGs in grid s…
[v3-3-test] Release DB connection before deserializing DAGs in grid s…
[v3-3-test] Release DB connection before deserializing DAGs in grid s…