Skip to content

Commit f279151

Browse files
abdul-stripekaxil
authored andcommitted
[AIRFLOW-2145] fix deadlock on clearing running TI (#3657)
a `shutdown` task is not considered be `unfinished`, so a dag run can deadlock when all `unfinished` downstreams are all waiting on a task that's in the `shutdown` state. fix this by considering `shutdown` to be `unfinished`, since it's not truly a terminal state
1 parent b4f1c73 commit f279151

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

airflow/utils/state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def finished(cls):
101101
"""
102102
return [
103103
cls.SUCCESS,
104-
cls.SHUTDOWN,
105104
cls.FAILED,
106105
cls.SKIPPED,
107106
]
@@ -117,5 +116,6 @@ def unfinished(cls):
117116
cls.SCHEDULED,
118117
cls.QUEUED,
119118
cls.RUNNING,
119+
cls.SHUTDOWN,
120120
cls.UP_FOR_RETRY
121121
]

tests/models.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,26 @@ def test_dagrun_deadlock(self):
801801
dr.update_state()
802802
self.assertEqual(dr.state, State.FAILED)
803803

804-
def test_dagrun_no_deadlock(self):
804+
def test_dagrun_no_deadlock_with_shutdown(self):
805+
session = settings.Session()
806+
dag = DAG('test_dagrun_no_deadlock_with_shutdown',
807+
start_date=DEFAULT_DATE)
808+
with dag:
809+
op1 = DummyOperator(task_id='upstream_task')
810+
op2 = DummyOperator(task_id='downstream_task')
811+
op2.set_upstream(op1)
812+
813+
dr = dag.create_dagrun(run_id='test_dagrun_no_deadlock_with_shutdown',
814+
state=State.RUNNING,
815+
execution_date=DEFAULT_DATE,
816+
start_date=DEFAULT_DATE)
817+
upstream_ti = dr.get_task_instance(task_id='upstream_task')
818+
upstream_ti.set_state(State.SHUTDOWN, session=session)
819+
820+
dr.update_state()
821+
self.assertEqual(dr.state, State.RUNNING)
822+
823+
def test_dagrun_no_deadlock_with_depends_on_past(self):
805824
session = settings.Session()
806825
dag = DAG('test_dagrun_no_deadlock',
807826
start_date=DEFAULT_DATE)

0 commit comments

Comments
 (0)