From a02386a6e2abe1ee46a606eddbca37777e3e2183 Mon Sep 17 00:00:00 2001 From: George Menhorn Date: Wed, 8 Nov 2023 15:28:37 -0500 Subject: [PATCH] metrics: fix for pending jobs being delayed one or more frames The list of pending jobs was being traversed using an index that was unconditionally incremented, even after removing an item from the list. This could cause a job to be skipped in `SendPendingEvents`, at least until the next frame. This was not a fatal error as any skipped jobs would be handled in the later calls to SendPendingEvents (next tick). Noticed while auditing the code for a reported issue with dropped events. --- Runtime/Model/Metrics/MetricsSubmissionQueue.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Runtime/Model/Metrics/MetricsSubmissionQueue.cs b/Runtime/Model/Metrics/MetricsSubmissionQueue.cs index 4ef360e5..f3e0d32b 100644 --- a/Runtime/Model/Metrics/MetricsSubmissionQueue.cs +++ b/Runtime/Model/Metrics/MetricsSubmissionQueue.cs @@ -138,7 +138,7 @@ internal void SendPayload(ICollection events, uint attempts = 0) public void SendPendingEvents(float time) { - for (int index = 0; index < _submissionJobs.Count; index++) + for (int index = 0; index < _submissionJobs.Count; ) { var submissionJob = _submissionJobs.ElementAt(index); if (submissionJob.NextInvokeTime < time) @@ -146,6 +146,10 @@ public void SendPendingEvents(float time) SendPayload(submissionJob.Events, submissionJob.NumberOfAttempts); _submissionJobs.RemoveAt(index); } + else + { + index++; + } } }