Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Update value under concurrency fails when a cancellation token is registered. #184

@troydai

Description

@troydai

Scenario:

  1. Set up a memory cache.
  2. Add an entry with a cancellation token registered with it.
  3. Start a child thread which keep reading the memory cache with the same key.
  4. Reset the value of the entry from main thread.
  5. Exception InvalidOperationException is thrown.

Issue repo:

https://github.com/troydai/CachingIssues/blob/2a85107b9b572c47d66d2a0303deafecaeaa3166/TestActions/ConcurrencyIssue184.cs#L17

Run the sample follow exception will be thrown from child thread after the value is updated by main thread.

Unhandled Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Microsoft.Extensions.Caching.Memory.CacheEntry.PropageOptions(CacheEntry parent)
   at Microsoft.Extensions.Caching.Memory.MemoryCache.TryGetValue(Object key, Object& result)
   at Microsoft.Extensions.Caching.Memory.CacheExtensions.TryGetValue[TItem](IMemoryCache cache, Object key, TItem& value)
   at Microsoft.Extensions.Caching.Memory.CacheExtensions.Get[TItem](IMemoryCache cache, Object key)
   at ConsoleApplication.Program.<>c__DisplayClass5_0.<Monitor>b__0(Int32 round, DateTime beginning)
   at ConsoleApplication.Program.<>c__DisplayClass4_0.<Polling>b__0()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions