Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix | Fix race condition issues between SinglePhaseCommit and TransactionEnded events #1042

Merged
merged 1 commit into from
Apr 23, 2021

Conversation

cheenamalhotra
Copy link
Member

@cheenamalhotra cheenamalhotra commented Apr 20, 2021

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

But as a consequence, "Commit"'s inconsistent locking leads to this problem. Locking is essential in this design, 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. Making test-case more rigorous and forcing latency while debugging aided in reproducing this issue.

Link to Repro.
Possibly also related to issue #729 (repro)

P.S. Fix tested with System.Data.SqlClient in debug session.
cc @saurabh500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants