Fix structured log write buffer shutdown flush (#7460)

* Fix structured log write buffer shutdown flush

* Address structured log buffer review feedback
This commit is contained in:
Sipke Schoorstra 2026-05-17 19:33:29 +02:00 committed by GitHub
parent 8416ea8af4
commit 60e742b0e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
}
}
}