Skip to content

Commit 9d4ef01

Browse files
committed
Fix issue that could cause DB connections to leak
1 parent 2b06f57 commit 9d4ef01

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

OrangeLoop.Sagas/DatabaseUnitOfWork.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ public class DatabaseUnitOfWork : IUnitOfWork
88
{
99
public DatabaseUnitOfWork(IDbConnection connection, IUnitOfWorkConfig config)
1010
{
11+
Connection = connection;
1112
Transaction = connection.BeginTransaction(config.IsolationLevel);
1213
}
1314

1415
public IDbTransaction Transaction { get; private set; }
16+
private IDbConnection Connection { get; set; }
1517

1618
public void Commit()
1719
{
1820
try
1921
{
2022
Transaction.Commit();
21-
Transaction.Connection?.Close();
23+
Connection?.Close();
2224
}
2325
catch(Exception)
2426
{
@@ -28,7 +30,7 @@ public void Commit()
2830
finally
2931
{
3032
Transaction?.Dispose();
31-
Transaction?.Connection?.Dispose();
33+
Connection?.Dispose();
3234
Transaction = null;
3335
}
3436
}
@@ -38,7 +40,7 @@ public void Rollback()
3840
try
3941
{
4042
Transaction.Rollback();
41-
Transaction.Connection?.Close();
43+
Connection?.Close();
4244
}
4345
catch
4446
{
@@ -47,14 +49,14 @@ public void Rollback()
4749
finally
4850
{
4951
Transaction?.Dispose();
50-
Transaction?.Connection?.Dispose();
52+
Connection?.Dispose();
5153
Transaction = null;
5254
}
5355
}
5456

5557
public void Dispose()
5658
{
57-
if (Transaction?.Connection?.State == System.Data.ConnectionState.Open)
59+
if (Connection?.State == System.Data.ConnectionState.Open)
5860
{
5961
Rollback();
6062
}

OrangeLoop.Sagas/OrangeLoop.Sagas.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageProjectUrl>https://github.com/orangeloop/sagas</PackageProjectUrl>
1111
<RepositoryUrl>https://github.com/orangeloop/sagas</RepositoryUrl>
1212
<RepositoryType>git</RepositoryType>
13-
<PackageTags>C#, ASP.NET Core, Sagas, Microservices,</PackageTags>
13+
<PackageTags>C#, ASP.NET Core, .NET Core, Sagas, Microservices, UnitOfWork, Unit of Work</PackageTags>
1414
<NeutralLanguage>en</NeutralLanguage>
1515
<Description>A simple C# implementation of the Unit of Work pattern for use with IDbConnection, as well a Saga implementation for orchestrating transactions across domains.</Description>
1616
<Version>1.0.0</Version>

0 commit comments

Comments
 (0)