Skip to content

Commit

Permalink
Fix unknown transaction state issues when promoting delegated transac…
Browse files Browse the repository at this point in the history
…tion(Backport dotnet#1216)
  • Loading branch information
Kaur-Parminder committed Aug 23, 2021
1 parent 8908b92 commit ab024df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,22 @@ public byte[] Promote()
}

//Throw exception only if Transaction is still active and not yet aborted.
if (promoteException != null && Transaction.TransactionInformation.Status != TransactionStatus.Aborted)
if (promoteException != null)
{
throw SQL.PromotionFailed(promoteException);
try
{
// Safely access Transction status - as it's possible Transaction is not in right state.
if (Transaction?.TransactionInformation?.Status != TransactionStatus.Aborted)
{
throw SQL.PromotionFailed(promoteException);
}
}
catch (TransactionException te)
{
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Promote | RES | CPOOL | Object Id {0}, Client Connection Id {1}, Transaction exception occurred: {2}.", ObjectID, usersConnection?.ClientConnectionId, te.Message);
// Throw promote exception if transaction state is unknown.
throw SQL.PromotionFailed(promoteException);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,22 @@ public Byte[] Promote()
}

//Throw exception only if Transaction is still active and not yet aborted.
if (promoteException != null && Transaction.TransactionInformation.Status != SysTx.TransactionStatus.Aborted)
if (promoteException != null)
{
throw SQL.PromotionFailed(promoteException);
try
{
// Safely access Transction status - as it's possible Transaction is not in right state.
if (Transaction?.TransactionInformation?.Status == SysTx.TransactionStatus.Aborted)
{
throw SQL.PromotionFailed(promoteException);
}
}
catch (SysTx.TransactionException te)
{
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Promote | RES | CPOOL | Object Id {0}, Client Connection Id {1}, Transaction exception occurred: {2}.", ObjectID, usersConnection?.ClientConnectionId, te.Message);
// Throw promote exception if transaction state is unknown.
throw SQL.PromotionFailed(promoteException);
}
}
else
{
Expand Down

0 comments on commit ab024df

Please sign in to comment.