Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: InvalidOperationException: Collection was modified; enumeration operation may not execute. #865

Open
furoTmark opened this issue Feb 3, 2025 · 0 comments

Comments

@furoTmark
Copy link

furoTmark commented Feb 3, 2025

Description

When running an indexing job for Algolia, we experience this an InvalidOperationException error intermittently.
The code is the following:

var batchResponses = await _client.SaveObjectsAsync(_indexName, dtos, cancellationToken: _token);
var taskResponses = new List<GetTaskResponse>();

foreach (var batchResponse in batchResponses)
{
    var taskResponse = await _client.WaitForTaskAsync(_indexName, batchResponse.TaskID, ct: _token);
    taskResponses.Add(taskResponse);
}

return taskResponses.Any(x => x.Status == TaskStatus.NotPublished);

From the stacktrace (that is added in the log output), it is an issue in the HttpRequestHeadersExtensions.Fill method probably comes from AlgoliaHttpRequester.SendRequestAsync line 70 ( httpRequestMessage.Headers.Fill(request.Headers); )

Client

Search

Version

7.4.1

Relevant log output

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
   at Algolia.Search.Http.HttpRequestHeadersExtensions.Fill(HttpRequestHeaders headers, IDictionary`2 dictionary)
   at Algolia.Search.Http.AlgoliaHttpRequester.<SendRequestAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Algolia.Search.Transport.HttpTransport.<ExecuteRequestAsync>d__10`2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Algolia.Search.Transport.HttpTransport.<ExecuteRequestAsync>d__8`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Algolia.Search.Clients.SearchClient.<GetTaskAsync>d__72.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Algolia.Search.Clients.SearchClient.<>c__DisplayClass131_0.<<WaitForTaskAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Algolia.Search.Clients.SearchClient.<RetryUntil>d__149`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Algolia.Search.Clients.SearchClient.<WaitForTaskAsync>d__131.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at <<REDACTED>>.Algolia.AlgoliaIndexingJob.<CheckIfPublishedNotCompleted>d__55.MoveNext() in <<REDACTED>>
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at <<REDACTED>>.Algolia.AlgoliaIndexingJob.<IndexBatch>d__42.MoveNext() in <<REDACTED>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant