Skip to content

Deadlock between SinglePhaseEnlistment.Aborted() and DbConnectionInternal.DetachTransaction() #1124

Closed

Description

@DavidBoike

Describe the bug

Starting with 2.1.3, we experienced deadlocking issues when a TransactionScope is disposed. Either the code should fully commit, or it should throw a TransactionAbortedException or some such, but instead it just hangs on the end of the using block where the TransactionScope is disposed.

May be an unintended consequence of #1049, the deadlock does not occur in 2.1.2 but does occur in 2.1.3 and 3.0.0.

At Particular Software we have a test for our SQL Transport designed to ensure that certain things happen when a transaction is aborted that was deadlocking every single time. We were able to slim this down into a minimal repro.

We have another situation where we were spinning up two connections to the same server to test the database's support for DTC. This was also hanging but it appeared like a race condition. The repro below happens consistently.

To reproduce

The code in this gist is a minimal reproduction of the problem.

  1. Run pointed at a local SQL Express instance, or change the connection string to match.
  2. As written (using v2.1.3) it will hang and never complete.
  3. Changing to v2.1.2 (and being sure to rebuild) will result in an a TransactionAbortedException being quickly thrown, caught, and printed to the console, after which the program will complete.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

Expected behavior

Should throw TransactionAbortedException instead of hanging.

Further technical details

  • Microsoft.Data.SqlClient version: 2.1.3 or 3.0.0
  • .NET target: .NET Framework 4.7.2
  • SQL Server version: Microsoft SQL Server 2019 (RTM-GDR) (KB4583458) - 15.0.2080.9 (X64) Nov 6 2020 16:50:01 Copyright (C) 2019 Microsoft Corporation Express Edition (64-bit) on Windows 10 Home 10.0 (Build 19042: ) (Hypervisor)
  • Operating system: Windows 10 Home (10.0.19042 Build 19042)

Activity

  1. cheenamalhotra commented on Jun 17, 2021

    @cheenamalhotra
    Member

    Hi @DavidBoike

    It is indeed a bug for DTC in .NET Framework.
    I'm able to reproduce it as well. Thanks for bringing it to us with repro.

    Just to add more info, this isn't reproducible in .NET Core as distributed transactions are not supported in .NET Core.
    PR #1049 was fixing a .NET Core related issue, so distributed transactions were most likely missed out.

    Our team will investigate and get back on this soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions