-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Make concurrent reads on HttpHeaders thread-safe #68115
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue DetailsFixes #61798 Adds no overhead if headers are both added & enumerated without validation.
|
@dotnet/ncl PTAL The change boils down to adding a
Since a value entry can transition from being a The code also has to be careful when reading the value of a given entry. if (entries[i].Value is HeaderStoreItemInfo)
{
// ...
}
else
{
DoSomething((string)entries[i].Value); // Wrong! The value may now be HeaderStoreItemInfo
} and it should instead be something like object value = entries[i].Value;
if (value is HeaderStoreItemInfo)
{
// ...
}
else
{
DoSomething((string)value);
} I've looked through our current code to make sure this is the case, but it's possible future changes may accidentally break this. I've added a test that should catch most such mistakes, but there may be cases that aren't covered. |
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.
LGTM, but maybe someone else could also take a look 🙂
src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeadersTest.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Show resolved
Hide resolved
Does this change fully address #61798 ? I see the issue mentioning invalid values too, but this change only adds locks? |
Will this change be in an upcoming version 6 update? If so, any idea when? |
It will be in preview 5 of .NET 7. If you mean whether it will be backported to 6.0, there are currently no plans for that. |
Fixes #61798
Lowers the impact of bugs like #66989 and #65379.
Adds no overhead if headers are both added & enumerated without validation.
Simpler to review when hiding whitespace changes.