From c715d2e73e8855cf8044c860fe9d445af43f2504 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 20 Mar 2025 19:28:34 -0400 Subject: [PATCH] Fix audit forwarding when saga audit messages are enabled * fix null ref in Audit (#4894) fixes #4893 * Specify list capacity to avoid resizing * Use collection expression --------- Co-authored-by: Simon Cropp --- src/ServiceControl.Audit/Auditing/AuditIngestor.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ServiceControl.Audit/Auditing/AuditIngestor.cs b/src/ServiceControl.Audit/Auditing/AuditIngestor.cs index f783a61dea..bf48d23e96 100644 --- a/src/ServiceControl.Audit/Auditing/AuditIngestor.cs +++ b/src/ServiceControl.Audit/Auditing/AuditIngestor.cs @@ -70,8 +70,7 @@ public async Task Ingest(List contexts, CancellationToken cancel Task Forward(IReadOnlyCollection messageContexts, string forwardingAddress, CancellationToken cancellationToken) { - var transportOperations = new TransportOperation[messageContexts.Count]; //We could allocate based on the actual number of ProcessedMessages but this should be OK - var index = 0; + var transportOperations = new List(messageContexts.Count); MessageContext anyContext = null; foreach (var messageContext in messageContexts) { @@ -90,13 +89,12 @@ Task Forward(IReadOnlyCollection messageContexts, string forward // Forwarded messages should last as long as possible outgoingMessage.Headers.Remove(Headers.TimeToBeReceived); - transportOperations[index] = new TransportOperation(outgoingMessage, new UnicastAddressTag(forwardingAddress)); - index++; + transportOperations.Add(new TransportOperation(outgoingMessage, new UnicastAddressTag(forwardingAddress))); } return anyContext != null ? messageDispatcher.Value.Dispatch( - new TransportOperations(transportOperations), + new TransportOperations([.. transportOperations]), anyContext.TransportTransaction, cancellationToken) : Task.CompletedTask; }