Skip to content

Commit 21e6402

Browse files
bordingSimonCropp
andauthored
Fix audit forwarding when saga audit messages are enabled (#4906)
* fix null ref in Audit (#4894) fixes #4893 * Specify list capacity to avoid resizing * Use collection expression --------- Co-authored-by: Simon Cropp <[email protected]>
1 parent 3427fb4 commit 21e6402

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/ServiceControl.Audit/Auditing/AuditIngestor.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ public async Task Ingest(List<MessageContext> contexts)
9797

9898
Task Forward(IReadOnlyCollection<MessageContext> messageContexts, string forwardingAddress)
9999
{
100-
var transportOperations = new TransportOperation[messageContexts.Count]; //We could allocate based on the actual number of ProcessedMessages but this should be OK
101-
var index = 0;
100+
var transportOperations = new List<TransportOperation>(messageContexts.Count);
102101
MessageContext anyContext = null;
103102
foreach (var messageContext in messageContexts)
104103
{
@@ -117,13 +116,12 @@ Task Forward(IReadOnlyCollection<MessageContext> messageContexts, string forward
117116
// Forwarded messages should last as long as possible
118117
outgoingMessage.Headers.Remove(Headers.TimeToBeReceived);
119118

120-
transportOperations[index] = new TransportOperation(outgoingMessage, new UnicastAddressTag(forwardingAddress));
121-
index++;
119+
transportOperations.Add(new TransportOperation(outgoingMessage, new UnicastAddressTag(forwardingAddress)));
122120
}
123121

124122
return anyContext != null
125123
? messageDispatcher.Value.Dispatch(
126-
new TransportOperations(transportOperations),
124+
new TransportOperations([.. transportOperations]),
127125
anyContext.TransportTransaction
128126
)
129127
: Task.CompletedTask;
@@ -162,4 +160,4 @@ public async Task VerifyCanReachForwardingAddress()
162160
static readonly long FrequencyInMilliseconds = Stopwatch.Frequency / 1000;
163161
static readonly ILog Log = LogManager.GetLogger<AuditIngestor>();
164162
}
165-
}
163+
}

0 commit comments

Comments
 (0)