devCrowd-Team / fluent-cqrs

My Next Generation CQRS Framework for .Net Applications
MIT License
17 stars 7 forks source link

concurency issue (Collection was modified; enumeration operation may not execute) #9

Open dBug404 opened 8 years ago

dBug404 commented 8 years ago

i experience following error: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. bei System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) bei System.Collections.Generic.List1.Enumerator.MoveNextRare() bei System.Collections.Generic.List1.Enumerator.MoveNext() bei Fluent_CQRS.AggregateLifeCycle1.StoreChanges(ExecutionResult executionResult) bei Fluent_CQRS.AggregateLifeCycle1.TryStoreChanges(ExecutionResult executionResult)

I guess this is caused by multiple threads working with the same aggregate.

I am not sure, if this would be the responsibility of the framework to handle concurrency issues or the caller. I guess you could make arguments for both sides.

jfellien commented 8 years ago

Hi @dBug404, thanks for your message.

Is it possible for you to describe how to get this error, so it is more understandable for me?

THX

dBug404 commented 8 years ago

I've changed my code that only one thread can work at one aggregate at a time, but the problems still persisted.

After some debugging i took a look at the fluent-cqrs code and found out, that in the class AggregateLifeCycle the field _aggregate was static. So this could have never worked in a concurrent environment. Removing the static seems to work, but i just found it out, but the test i wrote to replicate the issue seems to work now.