Skip to content

Commit 54532bb

Browse files
authored
Move transaction commit logic outside the try-finally block (#13)
1 parent eb18d5f commit 54532bb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Core/MongoVault.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ public virtual async Task<int> SaveAsync(CancellationToken cancellationToken = d
119119
{
120120
await interceptor.SavedChangesAsync(interceptorContext, affected, cancellationToken);
121121
}
122-
123-
if (CurrentTransaction is null)
124-
{
125-
await session.CommitTransactionAsync(cancellationToken);
126-
}
127122
}
128123
catch (Exception e)
129124
{
@@ -139,9 +134,14 @@ public virtual async Task<int> SaveAsync(CancellationToken cancellationToken = d
139134

140135
throw;
141136
}
142-
finally
137+
138+
if (CurrentTransaction is null)
143139
{
144-
if (CurrentTransaction is null)
140+
try
141+
{
142+
await session.CommitTransactionAsync(cancellationToken);
143+
}
144+
finally
145145
{
146146
session.Dispose();
147147
}

0 commit comments

Comments
 (0)