Skip to content

Commit d13b4eb

Browse files
javiercnmayuki
andauthored
[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: Mayuki Sawatari <[email protected]>
1 parent 9876244 commit d13b4eb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Components/Components/src/Routing/QueryParameterValueSupplier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55
using System.Buffers;
6-
using System.Collections.Generic;
6+
using System.Collections.Concurrent;
77
using System.Diagnostics.CodeAnalysis;
88
using System.Reflection;
99
using Microsoft.AspNetCore.Components.Reflection;
@@ -17,7 +17,7 @@ internal sealed class QueryParameterValueSupplier
1717
{
1818
public static void ClearCache() => _cacheByType.Clear();
1919

20-
private static readonly Dictionary<Type, QueryParameterValueSupplier?> _cacheByType = new();
20+
private static readonly ConcurrentDictionary<Type, QueryParameterValueSupplier?> _cacheByType = new();
2121

2222
// These two arrays contain the same number of entries, and their corresponding positions refer to each other.
2323
// Holding the info like this means we can use Array.BinarySearch with less custom implementation.

0 commit comments

Comments
 (0)