Skip to content

Commit

Permalink
Addressed the issue where CapTransaction was not disposed when the tr…
Browse files Browse the repository at this point in the history
…ansaction failed for sql server. (#1521)
  • Loading branch information
yang-xiaodong committed May 7, 2024
1 parent 9e53295 commit 65cb6b2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/DotNetCore.CAP.SqlServer/Diagnostics/DiagnosticObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ public void OnNext(KeyValuePair<string, object?> evt)
if (_transBuffer.TryRemove(transactionKey, out var transaction))
{
if (GetProperty(evt.Value, "Operation") as string == "Rollback")
{
transaction.Dispose();
return;
}

transaction.DbTransaction = new NoopTransaction();
transaction.Commit();
transaction.Dispose();
transaction.Dispose();
}

break;
Expand All @@ -61,7 +65,10 @@ public void OnNext(KeyValuePair<string, object?> evt)
if (!TryGetSqlConnection(evt, out var sqlConnection)) return;
var transactionKey = sqlConnection.ClientConnectionId;

_transBuffer.TryRemove(transactionKey, out _);
if (_transBuffer.TryRemove(transactionKey, out var transaction))
{
transaction.Dispose();
}
}

break;
Expand Down

0 comments on commit 65cb6b2

Please sign in to comment.