-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Thread-safe HttpKnownHeaderNames initialization
#15519
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
Thread-safe HttpKnownHeaderNames initialization
#15519
Conversation
|
Even with this, the hashset will still be accessed from multiple threads concurrently in the cases given in #15513, won't it? We should probably add a test using the code samples in the issue to verify that this is sufficient to resolve it. Since the user reporting it mentioned that it was a bit intermittent, we should repeat their test a few times in our own tests. |
A root of the issue was that second thread read the HashSet while first thread still initializes the HashSet.
It's not worth it. We will not be able to make such tests stable and defensible. Please use compiled artifact to check locally. |
If the only writes are the ones when the object is generated : I think the write race condition is eliminated with this change. I am a C# dev, but I have zero knowledge on the Powershell source code. Hope I could help you somehow. |
@dperez83 PowerShell is great project to improve skills. It's too big to learn it well in a short time but you can pick an area you like best and work there with some workgroup https://devblogs.microsoft.com/powershell/powershell-working-groups/
|
PaulHigin
left a comment
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
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@daxian-dbw Could you please review? |
|
@SteveL-MSFT Could you please approve? It is impossible to merge without green flag :-) |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
I see that there's a pending review from @daxian-dbw Thank you |
|
@TravisEz13 Please review/approve. |
| if (s_contentHeaderSet == null) | ||
| { | ||
| s_contentHeaderSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
| // Thread-safe initialization. |
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.
| // Thread-safe initialization. | |
| // Thread-safe initialization because the constructor is only called once per AppDomain. |
HttpKnownHeaderNames initialization
|
🎉 Handy links: |
|
🎉 Handy links: |
PR Summary
Fix #15513
Move HttpKnownHeaderNames initialization to static constructor.
PR Context
See #15513.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).