Isolate per-dag-run failures in _schedule_all_dag_runs() to prevent single DagRun crashing the Scheduler#62893
Open
XD-DENG wants to merge 2 commits intoapache:mainfrom
Open
Conversation
cb28e4c to
8ae4c23
Compare
# What's the issue Previously, `_schedule_all_dag_runs()` used a list comprehension to process all DagRuns. If any `_schedule_dag_run()` raised an exception for any single dag run, the entire comprehension would abort, no other DagRun would be processed, and the exception would propagate up to crash the scheduler process — **stopping scheduling for ALL DAGs**. # How to reproduce While the specific scenario used to reproduce this (a TaskInstance with `state=UP_FOR_RETRY` and `end_date=NULL`) is nearly impossible under normal operation, the lack of **per-dag-run fault isolation** means ANY unexpected exception from ANY DagRun would have the same fatal effect. #What's the fix Replace the list comprehension with an explicit loop that catches exceptions per DagRun, logs the error with full traceback, and continues processing the remaining DagRuns.
7d1a8b2 to
c915fd5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the issue
Previously,
_schedule_all_dag_runs()used a list comprehension to process all DagRuns. If any_schedule_dag_run()raised an exception for any single dag run, the entire comprehension would abort, no other DagRun would be processed, and the exception would propagate up to crash the scheduler process — stopping scheduling for ALL DAGs.How to reproduce
I tried to run a DagRun then go to database to mark one TaskInstace's state to
up_for_retryand theend_datetoNone. In this case, the scheduler simply crashed with the error below:While the specific scenario used to reproduce this (a TaskInstance with
state=UP_FOR_RETRYandend_date=NULL) is nearly impossible under normal operation, the lack of per-dag-run fault isolation means ANY unexpected exception from ANY DagRun would have the same fatal effect.(tested with Airflow 3.1.7)
What's the fix
Replace the list comprehension with an explicit loop that catches exceptions per DagRun, logs the error with full traceback, and continues processing the remaining DagRuns as well as the future DagRuns.
Was generative AI tooling used to co-author this PR?
Generated-by: [Claude Opus 4.6] following the guidelines
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.