From 60e742b0e30f37503156e96c56ce5ade8a99ade9 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sun, 17 May 2026 19:33:29 +0200 Subject: [PATCH] Fix structured log write buffer shutdown flush (#7460) * Fix structured log write buffer shutdown flush * Address structured log buffer review feedback --- .../Services/StructuredLogWriteBuffer.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/modules/Elsa.Diagnostics.StructuredLogs.Persistence.Relational/Services/StructuredLogWriteBuffer.cs b/src/modules/Elsa.Diagnostics.StructuredLogs.Persistence.Relational/Services/StructuredLogWriteBuffer.cs index 81ea41789..719194a96 100644 --- a/src/modules/Elsa.Diagnostics.StructuredLogs.Persistence.Relational/Services/StructuredLogWriteBuffer.cs +++ b/src/modules/Elsa.Diagnostics.StructuredLogs.Persistence.Relational/Services/StructuredLogWriteBuffer.cs @@ -149,17 +149,18 @@ public class StructuredLogWriteBuffer( private async Task ProcessQueueAsync() { - using var timer = new PeriodicTimer(options.Value.WriteQueue.FlushInterval); var cancellationToken = _stopTokenSource.Token; while (!cancellationToken.IsCancellationRequested) { try { - var signalTask = _signal.WaitAsync(cancellationToken); - var timerTask = timer.WaitForNextTickAsync(cancellationToken).AsTask(); - await Task.WhenAny(signalTask, timerTask); - await FlushAsync(cancellationToken); + await _signal.WaitAsync(options.Value.WriteQueue.FlushInterval, cancellationToken); + + if (cancellationToken.IsCancellationRequested) + return; + + await FlushAsync(); } catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) { @@ -169,9 +170,12 @@ public class StructuredLogWriteBuffer( { return; } - catch (Exception e) when (!cancellationToken.IsCancellationRequested) + catch (Exception e) { Trace.TraceError("Failed to flush structured log writes: {0}", e); + + if (cancellationToken.IsCancellationRequested) + return; } } }