Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

[Release/3.1] Fix race condition issues between SinglePhaseCommit and TransactionEnded events #43070

Merged
merged 1 commit into from
May 6, 2021

Conversation

cheenamalhotra
Copy link
Member

@cheenamalhotra cheenamalhotra commented Apr 26, 2021

Ports dotnet/sqlclient#1042 to fix below issue in System.Data.SqlClient:

Summary

A race condition exists between "Single Phase Commit" and "Transaction Ended" as both are triggered externally by delegated SqlTransaction. With new changes to doom connection in "Transaction Ended" Event (#42937), "Commit" started failing intermittently leading to this issue. Dooming connection is essential to prevent connection re-use that leads to security issues, so that PR is valid and important.

But as a consequence, "Commit"'s inconsistent locking leads to this problem. Locking is essential in this part of code, but in "Single Phase Commit" implementation, late and split locking causes issues between Commit and Abort event handling, leading to intermittent "Transaction Aborted Exception".

This change in lock scope fixes the issue. It wasn't easily reproducible in Microsoft.Data.SqlClient but happens very often with System.Data.SqlClient 4.8.2 due to slow performance. Making test-case more rigorous and forcing latency while debugging aided in reproducing this issue.

Customer Impact

Critical: Premier customer application is impacted due to this issue (followed via Emails).

Regression?

Yes: Issue started occurring since System.Data.SqlClient v4.8.2 (PR #42937)

Testing

It's not possible to add test case for this behavior since it's a race condition scenario and is greatly influenced by MS DTC that manages delegated transaction completion.

Risk

Low: This PR does not introduce any critical design changes, but only makes changes in lock scope.
Issue has been verified by customers as well as with the repro apps available in issue #729

cc: @danmoseley @saurabh500 @David-Engel

@cheenamalhotra cheenamalhotra added the Servicing-consider Issue for next servicing release review label Apr 28, 2021
@aik-jahoda
Copy link

We have open branch, please mark the PR with Servicing-approved tag once approved.

@leecow leecow added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels May 6, 2021
@leecow leecow added this to the 3.1.17 milestone May 6, 2021
@danmoseley danmoseley merged commit d5162f1 into dotnet:release/3.1 May 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants