Repository navigation
Task starts time out on PUT /rtif after the 3.3.2 to 3.4.0 upgrade #76774
Replies: 4 comments
What the code does
So the cleanup is on the task-start critical path, in the same transaction as the upsert, and it runs on every task start. Why the v2 DELETE is expensiveThe v2 statement ( delete(cls).where(
select(1).where(
TaskInstance.id == cls.task_instance_id,
TaskInstance.dag_id == dag_id,
TaskInstance.task_id == task_id,
TaskInstance.run_id.not_in(run_ids_to_keep),
).exists()
)
Either way the cost is proportional to the total size of
Why the v1 DELETE shows lock waits
Also note that after 3.4 nothing writes Your three questions
What I would do now
One more thing: |
|
+1 to @OswaldoRodriguez123's analysis. The unscoped v2 DELETE plus the unconditional v1 DELETE explains both wait-event patterns you captured. A few additions that may help with the issue and with preventing a repeat: 1. Abandoned requests keep running on the serverWith Until there's a fix, it's worth bounding this server-side, so a stuck cleanup fails fast instead of piling up. For example, set a role-level ALTER ROLE airflow SET lock_timeout = '5s';
ALTER ROLE airflow SET statement_timeout = '60s';Test this carefully first, because 2. The
|
|
Hi, building on what OswaldoRodriguez123 and Ahsan221B already found here. The cause looks like the rtif_v2 cleanup that came in with 3.4.0. On every task start it runs a DELETE that scans the task's whole attempt history to delete about one row, and that's what timed out your PUT /rtif calls. Issue #77237 measured the same thing: around 100 MB of reads to delete one row. For now, setting num_dag_runs_to_retain_rendered_fields=0 (needs an API server restart) and letting scheduled airflow db clean handle it instead should stop the timeouts. Running ANALYZE on rtif_v2 after the migration and raising execution_api_timeout above 5s are worth doing too. The real fix is the one in #77237, storing dag_id, task_id and run_id on rtif_v2 so the cleanup filters it directly. That issue is still open with no PR yet. |
|
I read the 3.4.0 code for this path, and the three comments above are right — I want to add verification, because I checked each claim against the source, and direct answers to your three questions. Diagnosis: the cleanup is on the task-start critical path, and the 3.4.0 rewrite made it O(your task's whole history) instead of O(rows deleted).
In 3.3.2 Two more things from the code that explain your wait events:
On your two hypotheses: both contributed, and the stats angle alone doesn't explain it. Your recovery at 17:03 lines up with the end of the post-migration burst and the first autovacuum, not the 17:07 autoanalyze — and in #77237 two MySQL deployments hit the same statements through lock contention and CPU saturation, with no stats angle at all. But the missing scoping is a defect regardless of the plan: with correct stats the planner would likely pick the semi-join that reads all 442k TIs, which is also slow. And the retry pile-up is real: with Your three questions:
What I would do now, in order:
How to confirm it worked: Credit where it is due: the root-cause analysis above is @OswaldoRodriguez123's and @Ahsan221B's, the measurements are from #77237, and the MySQL confirmations are from @vladosh84 and @diogosilva30 there. I verified each claim against the 3.4.0 source and |
Uh oh!
There was an error while loading. Please reload this page.
After we upgraded from 3.3.2 to 3.4.0, most tasks failed for about 10 minutes when they started, before user code ran. We cannot reproduce it on demand, so we ask here before we open an issue.
Setup
[workers] execution_api_timeout= 5 s,execution_api_retries= 5.shared_buffers128 MB,work_mem4 MB.task_instancehas 1.18M rows (2.8 GB). One(dag_id, task_id)has 442k rows.dag_runhas 1.02M rows. We did not runairflow db clean.What happened (UTC)
ReadTimeoutafter the Task SDK retriedPUT /execution/task-instances/{id}/rtif. Per minute, 21 to 39PUT /rtifrequests took more than 5 s on the server, and the maximum was 299 s.PATCH /runtook at most 8 s. 126 task starts sent 309PUT /rtifrequests.pg_stat_activityshowed about 20 active statements fromRenderedTaskInstanceFields.delete_old_records, whichti_put_rtifcalls on every task start (viaTaskInstance.update_rtif):PUT /rtifmaximum fell from 155 s (17:02) to 24 s (17:03), then 7 s (17:05). The first autovacuum ofrtif_v2ran at 17:03:11. The first autoanalyze ran at 17:07:11. The burst of task starts after the migration also ended at about that time.[core] num_dag_runs_to_retain_rendered_fields = 0(the new pods were up at 17:07).delete_old_recordsnow returns at once. It did not end the incident, because the recovery started before it.What we think happened
The
rtif_v2DELETE in 3.4.0 (from #74222) joinstask_instance. In 3.3.2 the cleanup was a DELETE onrendered_task_instance_fieldsthat its primary key covered. Now theEXPLAINof thertif_v2DELETE is cheap: a seq scan ofrtif_v2and onetask_instance_pkeylookup per row. We did not capture the plan during the incident, so we see two possible causes:rtif_v2had no statistics after the migration, and the planner started fromtask_instancethroughti_state_lkp (dag_id, task_id, run_id, state). That reads every run of the task (up to 442k rows) with a cold cache.PUT /rtifagain while the API server still ran the first request. Requests for the same task instance then waited on the same row locks.Questions
rtif_v1cleanup still runs on every task start after the migration tortif_v2?rtif_v2,xcom_v2andlegacy_task_data_ownerand does not runANALYZEon them. Our first autoanalyze ofrtif_v2came 14 minutes after the migration. Should the migration runANALYZE, or should deployments do it after the upgrade?num_dag_runs_to_retain_rendered_fields = 0with a scheduledairflow db cleana good long-term setting? Or is there a better way to keep this cleanup out of the task start path?If this looks like a bug, we can open an issue with this data.
Drafted-by: Claude Code (Opus 5.5); reviewed by @manucorujo before posting
All reactions