Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Deadlock on refresh from DB by local task run #25266

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,16 @@ def refresh_from_db(self, session: Session = NEW_SESSION, lock_for_update: bool
if lock_for_update:
for attempt in run_with_db_retries(logger=self.log):
with attempt:
from airflow.models.dagrun import DagRun # Avoid circular import

# Select the DagRun with a lock
with_row_locks(
session.query(DagRun).filter_by(
dag_id=self.dag_id,
run_id=self.run_id,
),
session=session,
).one()
ti: Optional[TaskInstance] = qry.with_for_update().first()
else:
ti = qry.first()
Expand Down