Skip to content

Commit

Permalink
[AIRFLOW-2145] fix deadlock on clearing running TI (#3657)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
abdul-stripe authored and ashb committed Sep 9, 2018
1 parent 794e478 commit dd2830d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion airflow/utils/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def finished(cls):
"""
return [
cls.SUCCESS,
cls.SHUTDOWN,
cls.FAILED,
cls.SKIPPED,
]
Expand All @@ -117,5 +116,6 @@ def unfinished(cls):
cls.SCHEDULED,
cls.QUEUED,
cls.RUNNING,
cls.SHUTDOWN,
cls.UP_FOR_RETRY
]
21 changes: 20 additions & 1 deletion tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,26 @@ def test_dagrun_deadlock(self):
dr.update_state()
self.assertEqual(dr.state, State.FAILED)

def test_dagrun_no_deadlock(self):
def test_dagrun_no_deadlock_with_shutdown(self):
session = settings.Session()
dag = DAG('test_dagrun_no_deadlock_with_shutdown',
start_date=DEFAULT_DATE)
with dag:
op1 = DummyOperator(task_id='upstream_task')
op2 = DummyOperator(task_id='downstream_task')
op2.set_upstream(op1)

dr = dag.create_dagrun(run_id='test_dagrun_no_deadlock_with_shutdown',
state=State.RUNNING,
execution_date=DEFAULT_DATE,
start_date=DEFAULT_DATE)
upstream_ti = dr.get_task_instance(task_id='upstream_task')
upstream_ti.set_state(State.SHUTDOWN, session=session)

dr.update_state()
self.assertEqual(dr.state, State.RUNNING)

def test_dagrun_no_deadlock_with_depends_on_past(self):
session = settings.Session()
dag = DAG('test_dagrun_no_deadlock',
start_date=DEFAULT_DATE)
Expand Down

0 comments on commit dd2830d

Please sign in to comment.