jet / equinox

.NET event sourcing library with CosmosDB, DynamoDB, EventStoreDB, message-db, SqlStreamStore and integration test backends. Focused at stream level; see https://github.com/jet/propulsion for cross-stream projections/subscriptions/reactions
https://github.com/jet/dotnet-templates
Apache License 2.0
471 stars 68 forks source link

fix(Caching): Correct Cancellation Handling #451

Closed bartelink closed 7 months ago

bartelink commented 7 months ago

Where the request being processed via the read through cache mechanism gets Cancelled (via CancellationTokenSource, but also via things like Async.Parallel's cancellation of sibling requests), the Task held within the LazyTask ends up in Cancelled state, not the more typical IsFaulted.

This leads to incorrect re-use of the cached value (as held within the cell).

This in turn leads to any request with AnyCachedValue (or AllowStale) in 4.0.0 failing with TaskCancelledException for as long as that cache entry lives.


While this is a relatively obvious mistake, the issue is only reproducable with very heavy parallism - and it's only in cache read through mode (allowStale > TimeSpan.Zero) that this comes into play.