dotnet/runtime

Possible thread safety issue with linked cache entries

Open

#46,032 创建于 2020年12月14日

在 GitHub 查看
 (4 评论) (2 反应) (0 负责人)C# (5,445 fork)batch import
area-Extensions-Cachingbughelp wanted

仓库指标

Star
 (17,886 star)
PR 合并指标
 (平均合并 12天 11小时) (30 天内合并 661 个 PR)

描述

As noticed by @gfoidl in https://github.com/dotnet/runtime/pull/45962/files#r541573802

It's possible that when the following code responsible for propagating the options to the linked cache entry:

https://github.com/dotnet/runtime/blob/8d6e098d647bd59a79165c3ad6b31957999479bb/src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs#L329-L341

calls the parent.AddExpirationToken method:

https://github.com/dotnet/runtime/blob/1d9e50cb4735df46d3de0cee5791e97295eaf588/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/CacheEntryExtensions.cs#L40

is using _expirationTokens which might be used without a lock in the CheckForExpiredTokens method at the same time

https://github.com/dotnet/runtime/blob/8d6e098d647bd59a79165c3ad6b31957999479bb/src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs#L207-L229

Adding a lock to CheckForExpiredTokens would be trivial, but it would hurt the perf...

贡献者指南