-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3.1.2] Backport: Release connection lock before signaling SinglePhas…
…eCommit completion (#1912) [3.1.2] Backport: Release connection lock before signaling SinglePhaseCommit completion #1912
- Loading branch information
1 parent
523a1ee
commit 9f8117a
Showing
4 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
45 changes: 45 additions & 0 deletions
45
...rosoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/DistributedTransactionTest.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using System.Transactions; | ||
using Xunit; | ||
|
||
#if NET7_0_OR_GREATER | ||
|
||
namespace Microsoft.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
[PlatformSpecific(TestPlatforms.Windows)] | ||
public class DistributedTransactionTest | ||
{ | ||
private static bool s_DelegatedTransactionCondition => DataTestUtility.AreConnStringsSetup() && DataTestUtility.IsNotAzureServer() && PlatformDetection.IsNotX86Process; | ||
|
||
[ConditionalFact(nameof(s_DelegatedTransactionCondition), Timeout = 10000)] | ||
public async Task Delegated_transaction_deadlock_in_SinglePhaseCommit() | ||
{ | ||
TransactionManager.ImplicitDistributedTransactions = true; | ||
using var transaction = new CommittableTransaction(); | ||
|
||
// Uncommenting the following makes the deadlock go away as a workaround. If the transaction is promoted before | ||
// the first SqlClient enlistment, it never goes into the delegated state. | ||
// _ = TransactionInterop.GetTransmitterPropagationToken(transaction); | ||
await using var conn = new SqlConnection(DataTestUtility.TCPConnectionString); | ||
await conn.OpenAsync(); | ||
conn.EnlistTransaction(transaction); | ||
|
||
// Enlisting the transaction in second connection causes the transaction to be promoted. | ||
// After this, the transaction state will be "delegated" (delegated to SQL Server), and the commit below will | ||
// trigger a call to SqlDelegatedTransaction.SinglePhaseCommit. | ||
await using var conn2 = new SqlConnection(DataTestUtility.TCPConnectionString); | ||
await conn2.OpenAsync(); | ||
conn2.EnlistTransaction(transaction); | ||
|
||
// Possible deadlock | ||
transaction.Commit(); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains 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