fix: avoid entry author deadlocks - #19363
Open
mvanhorn wants to merge 1 commit into
Open
Conversation
Member
|
Thanks for the PR! You’ve got a couple PhpStan issues to address in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Change
Entry::_saveAuthors()to use the existingDb::deleteIfExists()helper forentries_authors, which performs the delete only when matching rows exist and was designed to avoid deadlocks caused by deleting absent rows. Keep the existing author lookup and batch insert behavior intact so author replacement on established entries and initial author persistence continue to work across supported databases. Add a focused regression inEntriesTestthat observes the database commands for an initial authored-entry save versus an author update: the initial save must not execute a delete for its absent author rows, while the update must still remove the existing rows and persist the replacement author.Concurrent entry creation can intermittently deadlock on MySQL or MariaDB while
Entry::_saveAuthors()writes toentries_authors. The thread includes reproductions from queue jobs, load-balanced installations, Craft Cloud, and a core-only control-panel flow, with InnoDB diagnostics showing distinct new entry IDs contending on the primary-index supremum. The save path currently issues an unconditional delete for an entry ID before inserting its authors, even when a newly-created entry cannot have author rows yet. That empty-range delete can take a gap lock that conflicts with another transaction following the same delete-then-insert sequence.Fixes #15768
Related issues
Not applicable to this change.