Skip to content

Commit

Permalink
Release lock before signaling SinglePhaseCommit completion
Browse files Browse the repository at this point in the history
Fixes #1800
  • Loading branch information
roji committed Oct 9, 2022
1 parent fe8d1c1 commit 8f38613
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
RuntimeHelpers.PrepareConstrainedRegions();
try
{
Exception commitException = null;

lock (connection)
{
// If the connection is doomed, we can be certain that the
Expand All @@ -354,7 +356,6 @@ public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
}
else
{
Exception commitException;
try
{
// Now that we've acquired the lock, make sure we still have valid state for this operation.
Expand All @@ -364,7 +365,6 @@ public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
_connection = null; // Set prior to ExecuteTransaction call in case this initiates a TransactionEnd event

connection.ExecuteTransaction(SqlInternalConnection.TransactionRequest.Commit, null, System.Data.IsolationLevel.Unspecified, _internalTransaction, true);
commitException = null;
}
catch (SqlException e)
{
Expand Down Expand Up @@ -412,13 +412,14 @@ public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
}

connection.CleanupConnectionOnTransactionCompletion(_atomicTransaction);
if (commitException == null)
{
// connection.ExecuteTransaction succeeded
enlistment.Committed();
}
}
}

if (commitException == null)
{
// connection.ExecuteTransaction succeeded
enlistment.Committed();
}
}
catch (System.OutOfMemoryException e)
{
Expand Down

0 comments on commit 8f38613

Please sign in to comment.