-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release connection lock before signaling SinglePhaseCommit completion (…
- Loading branch information
Showing
3 changed files
with
51 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
42 changes: 42 additions & 0 deletions
42
...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,42 @@ | ||
// 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.Threading.Tasks; | ||
using System.Transactions; | ||
using Xunit; | ||
|
||
#if NET7_0_OR_GREATER | ||
|
||
namespace Microsoft.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
[PlatformSpecific(TestPlatforms.Windows)] | ||
public class DistributedTransactionTest | ||
{ | ||
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer), 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 |