-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Fix race condition when caching for a type of QueryParameterValueSupplier #40636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race condition when caching for a type of QueryParameterValueSupplier #40636
Conversation
src/Components/Components/src/Routing/QueryParameterValueSupplier.cs
Outdated
Show resolved
Hide resolved
src/Components/Components/src/Routing/QueryParameterValueSupplier.cs
Outdated
Show resolved
Hide resolved
src/Components/Components/src/Routing/QueryParameterValueSupplier.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Pranav K <prkrishn@hotmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/backport to release/6.0 |
Started backporting to release/6.0: https://github.com/dotnet/aspnetcore/actions/runs/1968359849 |
@Pilchie not sure why my permissions don't work? |
…ValueSupplier (#40636) * Use a concurrent dictionary to avoid race conditions.
@javiercn You have to flip the visibility if your |
@wtgodbe thanks |
…ValueSupplier (#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 <mayuki+github@misuzilla.org>
Description
Fixes #40595
QueryParameterValueSupplier.ForType
static method caches aQueryParameterValueSupplier
in the Dictionary for each type.The Dictionary for this cache is not locked and will be broken if multiple requests hit it on the first access.
This can also happen under heavy workloads or in cases such as health checks from load balancers at start-up.
It can be reproduced randomly by starting the Blazor Server with the following code running in a separate process.