Open ryan-nguyen-contemi opened 3 months ago
I'm personally not an EF expert. But wouldn't these line update the value?https://github.com/eventflow/EventFlow/blob/b277c52ea409c52e5f5b78f9cedfd0b3d399015d/Source/EventFlow.EntityFramework/ReadStores/EntityFrameworkReadModelStore.cs#L253-L255
You could also try providing a custom implementation for this class https://github.com/eventflow/EventFlow/blob/b277c52ea409c52e5f5b78f9cedfd0b3d399015d/Source/EventFlow/Core/RetryStrategies/OptimisticConcurrencyRetryStrategy.cs that adds some metrics to get some insights into the amount of times its happening. For a high load system it might simply be because the retry limit is reached.
Summary:
I faced the Optimisic Concurrency exception. After skimming through the code, I think that this only happens with
EntityFrameworkReadModelStore
. I will tell you my understanding and I seek for input from you who are more familiar with the source code.Description:
I cannot consistently reproduce the issue but it typically happens when multiple commands for the same aggregate ID are published within a short period of time.
Optimistic concurrency exceptions during read model updates might not be handled as expected, potentially leading to data inconsistency (i.e. events saved but not applied to read model).
It appears that reloading the read model from the database upon encountering an optimistic concurrency exception during read model updates might not be happening. This is due to the reuse of the same
DbContext
instance across retries during read model updates (see this code inEntityFrameworkReadModelStore
). Shouldn't there be aDbEntityEntry.Reload()
call somewhere to force readmodel reload?Stacktrace