Skip to content

fix: isolate advisory lock from other flush operations to prevent deadlocks#19684

Open
miketheman wants to merge 1 commit intopypi:mainfrom
miketheman:miketheman/deadlocks
Open

fix: isolate advisory lock from other flush operations to prevent deadlocks#19684
miketheman wants to merge 1 commit intopypi:mainfrom
miketheman:miketheman/deadlocks

Conversation

@miketheman
Copy link
Member

ensure_monotonic_journals acquired a global advisory lock in before_flush, then the same flush executed all pending INSERTs/UPDATEs.
When a File INSERT's unique constraint check waited on a concurrent transaction that was itself waiting for the advisory lock, a deadlock cycle formed.

Refactor the listener to automatically defer JournalEntries when other objects are also pending. The before_flush handler expunges them, and an after_flush handler restores them for a subsequent flush cycle where they're the only pending objects.
This ensures the advisory lock is never held while unrelated operations execute.

…dlocks

ensure_monotonic_journals acquired a global advisory lock in before_flush,
then the same flush executed all pending INSERTs/UPDATEs. When a File INSERT's
unique constraint check waited on a concurrent transaction that was itself
waiting for the advisory lock, a deadlock cycle formed.

Refactor the listener to automatically defer JournalEntries when other objects
are also pending. The before_flush handler expunges them, and an after_flush
handler restores them for a subsequent flush cycle where they're the only
pending objects. This ensures the advisory lock is never held while unrelated
operations execute.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@miketheman miketheman requested a review from a team as a code owner March 13, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant