Fix scheduler/triggerer deadlock on deferrable task instances#65920
Fix scheduler/triggerer deadlock on deferrable task instances#65920shaealh wants to merge 6 commits into
Conversation
|
Hi team, can I get an approval to merge? Thanks |
|
@shaealh — There are 4 unresolved review thread(s) on this PR from Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. Drafted-by: Claude Code (Opus 4.7); reviewed by @potiuk before posting |
|
@uranusjr fix has been pushed |
|
@shaealh can you rebase and resolve conflicts? |
|
Maybe this issue is solved within the context of this PR, WDYT? |
Regarding Issue #65818
related: #65836
This changes the scheduler trigger-timeout path and trigger cleanup path to lock candidate
task_instancerows in deterministic primary-key order before updating them.On MySQL/InnoDB, the previous bulk updates could reach overlapping
task_instancerows through different indexes, allowing the scheduler and triggerer to acquire row/gap locks in different orders. With HA schedulers and deferrable tasks, that can deadlock.The new flow is:
task_instance.idrows ordered by primary key.FOR UPDATE SKIP LOCKED.This keeps the existing predicates and update values intact while making lock acquisition consistent across the scheduler and triggerer writers.
Tests added:
Tests run:
ruff check airflow-core/src/airflow/jobs/scheduler_job_runner.py airflow-core/src/airflow/models/trigger.py airflow-core/tests/unit/jobs/test_scheduler_job.py airflow-core/tests/unit/models/test_trigger.pypython -m compileall -q airflow-core/src/airflow/jobs/scheduler_job_runner.py airflow-core/src/airflow/models/trigger.py airflow-core/tests/unit/jobs/test_scheduler_job.py airflow-core/tests/unit/models/test_trigger.pyAIRFLOW_HOME=/tmp/airflow-65818-test-home PATH=/tmp/airflow-test-bin:$PATH .venv/bin/python -m pytest airflow-core/tests/unit/models/test_trigger.py -k 'clean_unused' --with-db-initAIRFLOW_HOME=/tmp/airflow-65818-test-home PATH=/tmp/airflow-test-bin:$PATH .venv/bin/python -m pytest airflow-core/tests/unit/jobs/test_scheduler_job.py -k 'timeout_triggers' --with-db-initImportant
🛠️ Maintainer triage note for @shaealh · by
@potiuk· 2026-06-22 06:44 UTCThis PR is being closed to keep the review queue clean:
The ball is in your court — reopen this PR (or open a fresh one) once you've rebased onto
mainand resolved the conflicts. No rush.Automated triage — may be imperfect; a maintainer takes the next look.