Skip to content

Commit

Permalink
Better resource clean up on database operation batch. Closes GH-592
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Oct 16, 2023
1 parent 926291a commit 677967f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Persistence/Wolverine.RDBMS/Polling/DatabaseOperationBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async IAsyncEnumerable<object> ExecuteAsync(IWolverineRuntime runtime,
foreach (var operation in _operations) operation.ConfigureCommand(builder);

var cmd = builder.Compile();
var conn = cmd.Connection;
await using var conn = cmd.Connection;
await conn!.OpenAsync(cancellationToken);

var tx = await conn.BeginTransactionAsync(cancellationToken);
Expand All @@ -58,12 +58,18 @@ public async IAsyncEnumerable<object> ExecuteAsync(IWolverineRuntime runtime,
}
catch (Exception e)
{
await conn.CloseAsync();
throw new DatabaseBatchCommandException(cmd, e);
}

foreach (var command in _operations.SelectMany(x => x.PostProcessingCommands())) yield return command;

await conn.CloseAsync();
try
{
foreach (var command in _operations.SelectMany(x => x.PostProcessingCommands())) yield return command;
}
finally
{
await conn.CloseAsync();
}
}

public static async Task ApplyCallbacksAsync(IReadOnlyList<IDatabaseOperation> operations, DbDataReader reader,
Expand Down
4 changes: 4 additions & 0 deletions src/Wolverine/Tracking/EnvelopeHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public void RecordLocally(EnvelopeRecord record)
record.IsComplete = true;

break;

case MessageEventType.Requeued:
// Do nothing, just informative
break;

default:
throw new ArgumentOutOfRangeException(nameof(record.MessageEventType), record.MessageEventType, null);
Expand Down

0 comments on commit 677967f

Please sign in to comment.