Repository navigation
Roll back a take that lost the first insert of a lock name - #3210
Merged
Merged
Conversation
pournasserian
added a commit
that referenced
this pull request
Nov 16, 2026
…3216) Brings `main` at f8ff094 into `feature/a1`, as a merge commit, so that the feature branch is tested with what `main` gained since the last sync: - #3210: a take of the row lock that loses the first insert of a name rolls back before it reads the row (the `Templates` failure of #3200). - #3208: the delivery cache tests deliver the grant's eviction before the shared-store reads (#3201). - #3199: a confirmed logout revokes the authorizations of the session it ends (#3198). One conflict, in the "Multi-instance as built" paragraph of `docs/planning/backend-technical-spec.md`: `main`'s text is taken, and the feature branch's own change to the paragraph on the commands in the reference host is kept. With #3199 in, `docs/decisions/0007-admin-sign-in-flow.md` says what a logout ends: an unconfirmed one leaves the server's session and its tokens; a confirmed one ends the session and revokes every authorization issued in it; a sign-in from before #3198 and a third-party client's consent are not ended. ## Dependencies None. Part of #3152.
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.
Closes #3200
Since #3182 the take of the row lock runs in an explicit transaction. On the first use of a name, takes that start together race on the insert of its row. A loser's insert fails with a unique violation, and in
catch (DbUpdateException)it calledExistsAsync, which readscms_lockon another connection while the loser's own transaction is still open. On the in-memory SQLite database ofFluentCmsTestHost(shared cache), that open transaction holds the write lock, so the read gotSQLITE_LOCKEDand retried for the 30-second command timeout. Meanwhile other takes overshot their waits and the holder's own write failed withdatabase table is locked, which was the 500 of the plugin template'sPostsSentTogetherAddNoMoreNotesThanTheSettingsAllowin theTemplatesjob. The take now rolls its transaction back before it reads the row, asSaveChangesAsyncdid before #3182. The backend spec's "Multi-instance as built" paragraph gets one sentence on it. The preview release notes do not describe the lock change of #3182, so they are unchanged.What I checked in
DatabaseDistributedLock, by reading it:ExecuteUpdateAsyncpath of the take andRenewAsync's update run on the transaction's own context. When either throws,await usingdisposes the transaction (a rollback) before the caller'scatch, andIsBusyonly inspects the exception.RenewAsync's fallback read runs after its transaction is disposed, on the same context.ReleaseAsyncopens no explicit transaction, and the handle waits for its renewal loop to end before it releases.TryAcquireAsynconly waits after a null take and touches no database.ROLLBACK TOa savepoint, "short of rolling it back completely", as the way out of it (tutorial: transactions), so the rollback is allowed and needed, and a read in the same transaction would fail.SET XACT_ABORT OFF, the default and not changed anywhere in the code, a failed statement can roll back only that statement and leave the transaction open (SET XACT_ABORT), soRollbackends a pending transaction.SqlTransaction.RollbackthrowsInvalidOperationExceptiononly when the server already rolled the transaction back (SqlTransaction.Rollback), which a unique violation does not do withXACT_ABORT OFF.Measured by the diagnosing lane (the generated
Acme.ReviewNotestest, 20 runs per build under load):main)Measured here:
TakesThatRaceOnTheFirstUseOfANameEndWithinTheirTimeout, without the rollbackDistributedLockTestswith the rollback, SQLiteFluentCMS.Data.TestsMigrationsnamespace with the rollback, PostgreSQL 15Acme.ReviewNotesPostsSentTogetherAddNoMoreNotesThanTheSettingsAllowfrom packages of this branch, as theTemplatesjob makes itThe new test runs ten takes with a 500 ms wait on a name never used before, on the in-memory database. Exactly one holds the lock: the lease is 30 seconds on a wall clock that does not move, and nobody releases before the count.
Dependencies
None. #3195 follows this pull request and merges
mainafter it.Acceptance
main, in CI'sTemplatesjob, and the fix has a test in the repository's own tests if the cause is in the product (the regression test is inDistributedLockTests, and the generated test passed 20 runs locally; CI'sTemplatesjob onmainis not verified yet)