Skip to content
代码片段 群组 项目
未验证 提交 d13b4eb3 编辑于 作者: Javier Calvarro Nelson's avatar Javier Calvarro Nelson 提交者: GitHub
浏览文件

[Blazor] Fix race condition when caching for a type of...

[Blazor] Fix race condition when caching for a type of QueryParameterValueSupplier (#40636) (#40663)

## Description

We were using a regular dictionary on an internal cache that can be accessed concurrently.

#40595

## Customer Impact

If two or more threads try to populate the cache concurrently, it can cause the app to fail.

## Regression?

- [ ] Yes
- [X] No

[If yes, specify the version the behavior has regressed from]

## Risk

- [ ] High
- [ ] Medium
- [X] Low

It's switching the underlying dictionary type used.

## Verification

- [ ] Manual (required)
- [X] Automated

We have extensive E2E and unit tests for this behavior.

## Packaging changes reviewed?

- [ ] Yes
- [ ] No
- [X] N/A

Co-authored-by: default avatarMayuki Sawatari <mayuki+github@misuzilla.org>
上级 9876244c
No related branches found
No related tags found
无相关合并请求
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
using System; using System;
using System.Buffers; using System.Buffers;
using System.Collections.Generic; using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Reflection; using System.Reflection;
using Microsoft.AspNetCore.Components.Reflection; using Microsoft.AspNetCore.Components.Reflection;
...@@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Components.Routing ...@@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Components.Routing
{ {
public static void ClearCache() => _cacheByType.Clear(); public static void ClearCache() => _cacheByType.Clear();
private static readonly Dictionary<Type, QueryParameterValueSupplier?> _cacheByType = new(); private static readonly ConcurrentDictionary<Type, QueryParameterValueSupplier?> _cacheByType = new();
// These two arrays contain the same number of entries, and their corresponding positions refer to each other. // These two arrays contain the same number of entries, and their corresponding positions refer to each other.
// Holding the info like this means we can use Array.BinarySearch with less custom implementation. // Holding the info like this means we can use Array.BinarySearch with less custom implementation.
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册