From 677967f698797dde4f604728db42f0e2d1f4cf0f Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Mon, 16 Oct 2023 16:40:45 -0500 Subject: [PATCH] Better resource clean up on database operation batch. Closes GH-592 --- .../Polling/DatabaseOperationBatch.cs | 14 ++++++++++---- src/Wolverine/Tracking/EnvelopeHistory.cs | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Persistence/Wolverine.RDBMS/Polling/DatabaseOperationBatch.cs b/src/Persistence/Wolverine.RDBMS/Polling/DatabaseOperationBatch.cs index 029090b1a..c933b006f 100644 --- a/src/Persistence/Wolverine.RDBMS/Polling/DatabaseOperationBatch.cs +++ b/src/Persistence/Wolverine.RDBMS/Polling/DatabaseOperationBatch.cs @@ -41,7 +41,7 @@ public async IAsyncEnumerable 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); @@ -58,12 +58,18 @@ public async IAsyncEnumerable 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 operations, DbDataReader reader, diff --git a/src/Wolverine/Tracking/EnvelopeHistory.cs b/src/Wolverine/Tracking/EnvelopeHistory.cs index f8af08fcb..09ab16af4 100644 --- a/src/Wolverine/Tracking/EnvelopeHistory.cs +++ b/src/Wolverine/Tracking/EnvelopeHistory.cs @@ -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);