Document migration locking
See https://github.com/dotnet/efcore/pull/34115, https://github.com/dotnet/efcore/pull/34338
Update aka.ms/efcore-docs-migrations-lock
Show how to handle the situation where the lock is abandoned (uncommon, usually SQLite after terminating the app)
The aka.ms link only redirects to the Migrations Overview page without any details on the issue. I couldn't find anything about migration locks there.
This is misleading because stable EntityFrameworkCore 9 is already using and referring to this link. (Btw, this is on SQL Server and not SQLite)
Microsoft.EntityFrameworkCore.Migrations[20411]
Acquiring an exclusive lock for migration application. See https://aka.ms/efcore-docs-migrations-lock for more information if this takes too long.
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (30,116ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DECLARE @result int;
EXEC @result = sp_getapplock @Resource = '__EFMigrationsLock', @LockOwner = 'Session', @LockMode = 'Exclusive';
SELECT @result
Failed executing DbCommand (30,116ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DECLARE @result int;
EXEC @result = sp_getapplock @Resource = '__EFMigrationsLock', @LockOwner = 'Session', @LockMode = 'Exclusive';
SELECT @result
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (109ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DECLARE @result int;
EXEC @result = sp_releaseapplock @Resource = '__EFMigrationsLock', @LockOwner = 'Session';
SELECT @result
Failed executing DbCommand (109ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DECLARE @result int;
EXEC @result = sp_releaseapplock @Resource = '__EFMigrationsLock', @LockOwner = 'Session';
SELECT @result
Error Number:-2,State:0,Class:11
Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
cc @AndriySvyryd @maumar
@Trojaner the aka.ms link above is where docs would need to be added, and this issue tracks doing that. The EF 9 what's new docs discuss the new behavior.
@roji what I meant is that this link is already used in stable released versions but its still a placeholder.
Yes, we're aware - and this issue tracks adding the proper documentation instead of that placeholder. It's an undocumented feature.
Well that's kinda an interesting approach.
Because as you can see, this undocumented "feature" can cause obscure undocumented "errors" out of nowhere.
Like said, in this case I suddenly got an error about some timeout when attempting to place random locks on SQL Server while applying migrations via Update-Database. The error message refers to a link that does not really exist yet. As you have said, there is zero documentation on this and the end-user is just left guessing what they did wrong and how they can fix it. Once again, this is Microsoft.EntityFrameworkCore 9, a released stable and not a preview build. This doesn't seem to be up to the EntityFrameworkCore standards we are usually used to. Unless you somehow don't see a problem in this scenario.
Hence me pointing this out specifically.
@Trojaner yes, as I've already acknowledged above, the documentation is missing on a feature/change which has been released. This is not an ideal situation - we try to document everything before or soon after a release - but it sometimes can happen, as resources and competing priorities sometimes mean that we need to work on other things.
This issue tracks correcting this - I'm not sure what else can be said, or what exactly you're looking for here.
For some reason, every time Trojaner is mentioned here, I get a notification stating that I have been mentioned in an issue. Does anyone know why?
Huh, thats strange. Sounds like a GitHub bug?
Sorry if off-topic.
Huh, thats strange. Sounds like a GitHub bug?
Sorry if off-topic.
Don't mean to spam this thread, sorry, but it is actually a very weird bug. 😅