Skip to content

Return 5xx on database deadlock when updating task state - #75368

Merged
kaxil merged 1 commit into
apache:mainfrom
astronomer:ti-update-state-deadlock-retry
Oct 26, 2026
Merged

kaxil merged 1 commit into
apache:mainfrom
astronomer:ti-update-state-deadlock-retry

Conversation

@Lee-W

@Lee-W Lee-W commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

related: #71074

Why

A database deadlock is transient, but the catch-all in ti_update_state marks the task instance FAILED, which is permanent. The Task SDK client already retries Execution API 5xx responses, so letting the deadlock surface as a 500 gives the update another chance instead of failing the task.

What

ti_update_state now re-raises a deadlock error instead of marking the task instance FAILED, so the Execution API responds with a 500 and the Task SDK client retries. A new is_deadlock_error helper in airflow.utils.sqlalchemy recognizes Postgres 40P01 (psycopg2 pgcode and psycopg3 sqlstate) and MySQL 1213.

Only deadlocks are handled, so the existing callers of is_lock_not_available_error keep their behavior. Other database errors still mark the task instance FAILED as before. is_deadlock_error returns False on SQLite, which has no deadlock (only database is locked), so that case keeps the previous behavior.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [Claude] following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@boring-cyborg boring-cyborg Bot added area:API Airflow's REST/HTTP API area:task-sdk labels Oct 22, 2026
@Lee-W
Lee-W force-pushed the ti-update-state-deadlock-retry branch from c695588 to f5a37b3 Compare October 22, 2026 07:08
A deadlock is transient and the task would succeed on a retry, but the
catch-all around the state update marked the task instance FAILED, which
is permanent. The Task SDK client already retries 5xx responses from the
Execution API, so letting the deadlock surface as a 500 gives the worker
that retry.

Only deadlocks are treated this way. Recognising other lock errors would
change how existing callers of is_lock_not_available_error behave.
@Lee-W
Lee-W force-pushed the ti-update-state-deadlock-retry branch from f5a37b3 to 5dd4665 Compare October 22, 2026 10:35
@Lee-W
Lee-W marked this pull request as ready for review October 22, 2026 12:47
@Lee-W
Lee-W requested a review from kaxil October 22, 2026 12:47
@Lee-W
Lee-W enabled auto-merge (squash) October 26, 2026 10:49
@Lee-W Lee-W added the backport-to-v3-4-test Backport to v3-4-test label Oct 26, 2026
@kaxil
kaxil disabled auto-merge October 26, 2026 11:27
@kaxil
kaxil merged commit 840d3a4 into apache:main Oct 26, 2026
201 of 202 checks passed
@kaxil
kaxil deleted the ti-update-state-deadlock-retry branch October 26, 2026 11:28
@github-actions github-actions Bot added this to the Airflow 3.4.1 milestone Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.4.1 based on: backport label targeting v3-4-test
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-4-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-4-test PR Link

@Lee-W Lee-W modified the milestones: Airflow 3.4.1, Airflow 3.4.0 Oct 26, 2026
github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Oct 26, 2026
…pache#75368)

A deadlock is transient and the task would succeed on a retry, but the
catch-all around the state update marked the task instance FAILED, which
is permanent. The Task SDK client already retries 5xx responses from the
Execution API, so letting the deadlock surface as a 500 gives the worker
that retry.

Only deadlocks are treated this way. Recognising other lock errors would
change how existing callers of is_lock_not_available_error behave.
(cherry picked from commit 840d3a4)

Co-authored-by: Wei Lee <weilee@apache.org>
aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Oct 26, 2026
…pache#75368)

A deadlock is transient and the task would succeed on a retry, but the
catch-all around the state update marked the task instance FAILED, which
is permanent. The Task SDK client already retries 5xx responses from the
Execution API, so letting the deadlock surface as a 500 gives the worker
that retry.

Only deadlocks are treated this way. Recognising other lock errors would
change how existing callers of is_lock_not_available_error behave.
(cherry picked from commit 840d3a4)

Co-authored-by: Wei Lee <weilee@apache.org>
vatsrahul1001 pushed a commit that referenced this pull request Oct 26, 2026
…75368) (#75652)

A deadlock is transient and the task would succeed on a retry, but the
catch-all around the state update marked the task instance FAILED, which
is permanent. The Task SDK client already retries 5xx responses from the
Execution API, so letting the deadlock surface as a 500 gives the worker
that retry.

Only deadlocks are treated this way. Recognising other lock errors would
change how existing callers of is_lock_not_available_error behave.
(cherry picked from commit 840d3a4)

Co-authored-by: Wei Lee <weilee@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:task-sdk backport-to-v3-4-test Backport to v3-4-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants