-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[5.0.1] Disable savepoints on SQL Server when MARS is enabled #23305
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
@@ -249,6 +249,10 @@ | |||
<value>Skipping foreign key '{foreignKeyName}' on table '{tableName}' since all of its columns reference themselves.</value> | |||
<comment>Debug SqlServerEventId.ReflexiveConstraintIgnored string string</comment> | |||
</data> | |||
<data name="LogSavepointsDisabledBecauseOfMARS" xml:space="preserve"> | |||
<value>Savepoints are disabled because Multiple Active Result Sets is enabled. When saving changes, the transaction will not be rolled back if error occurs, and may be left in an unknown state. See https://docs.microsoft.com/en-us/ef/core/saving/transactions#savepoints for more information. To identify the code which triggers this warning, call 'ConfigureWarnings(w => w.Throw(RelationalEventId.SavepointsDisabledBecauseOfMARS))'.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get an fwlink for the doc link? See https://github.com/dotnet/EntityFramework.Docs/pull/2869ץ
/cc @JeremyLikness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this? https://go.microsoft.com/fwlink/?linkid=2149338 @roji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks @JeremyLikness!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing @JeremyLikness, can you please make it point specifically to the savepoints section of that page (https://docs.microsoft.com/en-us/ef/core/saving/transactions#savepoints)?
test/EFCore.SqlServer.FunctionalTests/MigrationsInfrastructureSqlServerTest.cs
Outdated
Show resolved
Hide resolved
@AndriySvyryd as discussed offline, TransactionSqlServerTest no longer disables MARS for the entire test suite. I looked at an attribute to not run a test if MARS is enabled/disabled, but ran into difficulties for retrieving the actual test class instance (in order to get the TestStore and check the connection string). However, there's currently exactly one inherited test which relies on MARS being disabled, so I just overrode and added that as a condition in the test for now. Let me know what you think. |
Are we adding a warning log in patch? |
IIRC we agreed to do this when discussing, as the warning would be emitted in cases where 5.0.0 currently fails. |
I missed that the warning happens only when asking is savepoints are enabled, which we only do when we're about to use one.
|
Approved by Tactics for 5.0.1. Let's get the forward link done and agree on any wording before merging. |
fd9bcb6
to
361ae11
Compare
361ae11
to
be99532
Compare
be99532
to
8e7bb1f
Compare
8e7bb1f
to
89f9315
Compare
89f9315
to
34239e7
Compare
Fixes #23269
Additional context for Tactics
This is a tricky one, because it is a regression in 5.0 resulting in an exception, the root cause of which is new feature added in 5.0. We don't want to break this new feature in 5.0.1 for people who are using it successfully in 5.0.0. Therefore, we are:
Description
EF Core 5.0 adds transaction savepoint support, and automatically uses savepoints to make SaveChanges better when an external transaction is used. Unfortunately savepoints do not work in SQL Server when the Multiple Active Result Set (MARS) feature is enabled.
Customer Impact
Regression for users who have turned on MARS and are using external transactions receive an error when attempting to save changes.
How found
User-reported on 5.0
Test coverage
Added in this PR. We will also revisit coverage for MARS in general.
Regression?
Yes, from 3.1.
Risk
Low. There was already infrastructure in place for checking whether savepoints are supported by the database provider or not; this PR modifies that check for SQL Server to check if MARS is enabled. When savepoints aren't supported, we revert back to the previous, 3.1 behavior.