Skip to content

Release TI lock before asset listener callbacks - #70951

Merged
vatsrahul1001 merged 4 commits into
apache:mainfrom
astronomer:fix/asset-registration-lock-contention
Aug 4, 2026
Merged

Release TI lock before asset listener callbacks#70951
vatsrahul1001 merged 4 commits into
apache:mainfrom
astronomer:fix/asset-registration-lock-contention

Conversation

@uranusjr

@uranusjr uranusjr commented Aug 2, 2026

Copy link
Copy Markdown
Member

Asset registration on the task-success path (ti_update_state) ran the listener hooks synchronously inside the transaction holding a row lock on the task_instance table. A slow listener, multiplied across a large fan-out of asset events, could hold that lock for minutes, causing statement timeouts.

The listener hooks are now deferred until the end of the endpoint instead of executed inline during asset event creation. Registration writes to the database still happen under the caller's transaction, so durability is unchanged; this only moves the best-effort listener hooks off the lock.

Close #66853.

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comments from my end, LGTM with this direction, thanks.

Comment thread airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py Outdated

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also address the loading issue that #66854 (comment) comment pointed out in this one? Since this PR is small enough. Thanks.

Asset registration on the task-success path (ti_update_state) ran the
listener hooks synchronously inside the transaction holding a row lock
on the task_instance table. A slow listener, multiplied across a large
fan-out of asset events, could hold that lock for minutes, causing
statement timeouts.

The listener hooks are now deferred until the end of the endpoint
instead of executed inline during asset event creation. Registration
writes to the database still happen under the caller's transaction, so
durability is unchanged; this only moves the best-effort listener hooks
off the lock.
@uranusjr
uranusjr force-pushed the fix/asset-registration-lock-contention branch from 1815493 to 1abae3e Compare August 3, 2026 08:59
Comment thread airflow-core/src/airflow/assets/manager.py

@kaxil kaxil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 minor comments lgtm otherwise

@eladkal eladkal added this to the Airflow 3.3.1 milestone Aug 3, 2026
@eladkal eladkal added type:bug-fix Changelog: Bug Fixes backport-to-v3-3-test Backport to v3-3-test labels Aug 3, 2026
@vatsrahul1001
vatsrahul1001 merged commit 79db995 into apache:main Aug 4, 2026
167 of 168 checks passed
@vatsrahul1001
vatsrahul1001 deleted the fix/asset-registration-lock-contention branch August 4, 2026 06:55
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-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-3-test PR Link

vatsrahul1001 pushed a commit that referenced this pull request Aug 4, 2026
…71065)

* [v3-3-test] Release TI lock before asset listener callbacks (#70951)

* Release TI lock before asset listener callbacks

Asset registration on the task-success path (ti_update_state) ran the
listener hooks synchronously inside the transaction holding a row lock
on the task_instance table. A slow listener, multiplied across a large
fan-out of asset events, could hold that lock for minutes, causing
statement timeouts.

The listener hooks are now deferred until the end of the endpoint
instead of executed inline during asset event creation. Registration
writes to the database still happen under the caller's transaction, so
durability is unchanged; this only moves the best-effort listener hooks
off the lock.

* Optimize asset alias assoc insert

* Fix exhausted iterator reuse bug

* Test asset reg callback cases
(cherry picked from commit 79db995)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* [v3-3-test] Explicitly rollback on task state update exception (#71076)

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Aug 5, 2026
…71065)

* [v3-3-test] Release TI lock before asset listener callbacks (#70951)

* Release TI lock before asset listener callbacks

Asset registration on the task-success path (ti_update_state) ran the
listener hooks synchronously inside the transaction holding a row lock
on the task_instance table. A slow listener, multiplied across a large
fan-out of asset events, could hold that lock for minutes, causing
statement timeouts.

The listener hooks are now deferred until the end of the endpoint
instead of executed inline during asset event creation. Registration
writes to the database still happen under the caller's transaction, so
durability is unchanged; this only moves the best-effort listener hooks
off the lock.

* Optimize asset alias assoc insert

* Fix exhausted iterator reuse bug

* Test asset reg callback cases
(cherry picked from commit 79db995)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* [v3-3-test] Explicitly rollback on task state update exception (#71076)

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:task-sdk backport-to-v3-3-test Backport to v3-3-test type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API server OOMKill: task_instance row lock held during asset event emission under high concurrency

7 participants