-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
Collection was modified; enumeration operation may not execute #398
Comments
Thanks for the report and the PR. Before I accept it though, I'd like to see a repro, preferably in the form of a test. |
I'm still not clear what specific scenario causes this error. Feel free to re-open if you can provide a repro. |
I thought the error is self explaining. I was using this lib in multiple threads. When 1 thread is removing an item while another was iterating the Queue then this error happens. I can't say for sure what particular operation on Flurl was causing iterating the queue. Actually it is clearly visible from callstack SendAsync is iterating. So the problem: 2 parallel calls to SendAsync cause this problem. The first one removes the item, while another one performs Any(), as result this exception is thrown. It is not easy to create a test which will reproduce a problem 100%. I had this problem in my test with 30-40% probability. Once I applied that change problem never occurred again. |
Ok great, I'll take another look. I was grooming the backlog and I don't really have a lot of patience for issues that don't have at least a minimal explanation to go with them. But you've provided that now, so all good. Thanks. |
I agree with what you did in your PR, but |
I agree this would be a breaking change. One option is to use ConcurrentQueue but the property is just returns snapshot Queue of the ConcurrentQueue |
But if you enqueue something on that snapshot, it wouldn't make it onto the Also, by sheer coincidence, I just repro'd this bug a few minutes ago while investigating #366. I think better concurrency in the testing framework will be a theme in 3.0. |
You right. That would not work. |
I'm going to close this issue, because it will be covered by #366. I've mentioned this specific exception there, but for tracking purposes I'd prefer to just keep one of them open. |
I am experiencing this issue also when trying to load data in parallel. |
This fix will go out in the next 3.0 prerelease. |
@tmenier do you have an estimation on when 3.0 will be released? |
@jpjohnson I don't have an estimate at this time. If the latest prerelease has what you need, I would suggest using it. It's stable. |
@tmenier thank you for your response. I will look at using the prerelease as we have run into this issue. |
Call failed. Collection was modified; enumeration operation may not execute. GET https://api.com?bla-bla)
----> Flurl.Http.FlurlHttpException : Call failed. Collection was modified; enumeration operation may not execute. GET https://api.com?bla-bla
----> System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
--InvalidOperationException
at System.Collections.Generic.Queue
1.Enumerator.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable
1 source)at Flurl.Http.Testing.HttpTest.GetNextResponse()
at Flurl.Http.Testing.FakeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption)
The text was updated successfully, but these errors were encountered: