GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Thread-safe `HttpKnownHeaderNames` initialization by iSazonov · Pull Request #15519 · PowerShell/PowerShell

Conversation

@iSazonov

@iSazonov Ilya (iSazonov) commented Jun 4, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

PR Summary

Fix #15513

Move HttpKnownHeaderNames initialization to static constructor.

PR Context

See #15513.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: or [ WIP ] to the beginning of the title (the WIP bot will keep its status check at Pending while the prefix is present) and remove the prefix when the PR is ready.
  • Breaking changes
    • None
    • OR
    • Experimental feature(s) needed
      • Experimental feature name(s):
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed
      • Issue filed:
  • Testing - New and feature
    • N/A or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
  • Tooling
    • I have considered the user experience from a tooling perspective and don't believe tooling will be impacted.
    • OR
    • I have considered the user experience from a tooling perspective and opened an issue in the relevant tool repository. This may include:
      • Impact on PowerShell Editor Services which is used in the PowerShell extension for VSCode
        (which runs in a different PS Host).
        • Issue filed:
      • Impact on Completions (both in the console and in editors) - one of PowerShell's most powerful features.
        • Issue filed:
      • Impact on PSScriptAnalyzer (which provides linting & formatting in the editor extensions).
        • Issue filed:
      • Impact on EditorSyntax (which provides syntax highlighting with in VSCode, GitHub, and many other editors).
        • Issue filed:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iSazonov
Thread-safe HttpKnownHeaderNames initialization
b4856dd
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jun 4, 2021
@iSazonov
Ilya (iSazonov) requested review from Paul Higinbotham (PaulHigin), Dongbo Wang (daxian-dbw) and Rain Sallow (/u/ta11ow) (vexx32) June 4, 2021 04:54
@iSazonov Ilya (iSazonov) self-assigned this Jun 4, 2021
@vexx32

Rain Sallow (/u/ta11ow) (vexx32) commented Jun 4, 2021

Copy link
Copy Markdown
Collaborator

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Jun 4, 2021

Copy link
Copy Markdown
Collaborator Author

Even with this, the hashset will still be accessed from multiple threads concurrently in the cases given in #15513, won't it?

A root of the issue was that second thread read the HashSet while first thread still initializes the HashSet.
The HashSet is used only in one place for reading so no need to concern more about race conditions.

We should probably add a test

It's not worth it. We will not be able to make such tests stable and defensible. Please use compiled artifact to check locally.

dperez83, PaulHigin, vexx32, and TravisEz13 reacted with thumbs up emoji
All reactions
  • 👍 4 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dperez83

dperez83 commented Jun 4, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Even with this, the hashset will still be accessed from multiple threads concurrently in the cases given in #15513, won't it?

A root of the issue was that second thread read the HashSet while first thread still initializes the HashSet.
The HashSet is used only in one place for reading so no need to concern more about race conditions.

We should probably add a test

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 :
s_contentHeaderSet.Add(HttpKnownHeaderNames.Allow);
s_contentHeaderSet.Add(HttpKnownHeaderNames.LastModified);
...

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Jun 4, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator Author

I am a C# dev, but I have zero knowledge on the Powershell source code. Help 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/
After monitoring issues and PRs for about a month you will be able to make good contributions.

PowerShell Team
PowerShell Working Groups | PowerShell Team
Since we open sourced PowerShell in 2016, PowerShell has been an immensely popular project on GitHub. Every year, 700-1000 PRs and 1300-1500 issues are submitted to the PowerShell repo, with roughly half of the PRs and 90% of the issues filed from the community.
dperez83 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

PaulHigin
Paul Higinbotham (PaulHigin) approved these changes Jun 4, 2021
View reviewed changes

@PaulHigin Paul Higinbotham (PaulHigin) left a comment

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TravisEz13 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
vexx32
Rain Sallow (/u/ta11ow) (vexx32) approved these changes Jun 4, 2021
View reviewed changes
@ghost ghost added the Review - Needed The PR is being reviewed label Jun 12, 2021
@ghost

Deleted user (ghost) commented Jun 12, 2021

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Jun 12, 2021

Copy link
Copy Markdown
Collaborator Author

Dongbo Wang (@daxian-dbw) Could you please review?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost ghost removed the Review - Needed The PR is being reviewed label Jun 12, 2021
@iSazonov

Ilya (iSazonov) commented Jun 18, 2021

Copy link
Copy Markdown
Collaborator Author

Steve Lee (@SteveL-MSFT) Could you please approve? It is impossible to merge without green flag :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost ghost added the Review - Needed The PR is being reviewed label Jun 25, 2021
@ghost

Deleted user (ghost) commented Jun 25, 2021

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dperez83

dperez83 commented Aug 4, 2021

Copy link
Copy Markdown

I see that there's a pending review from Dongbo Wang (@daxian-dbw)
Is there anything else you need from me?

Thank you

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov
Ilya (iSazonov) requested a review from Travis Plunk (TravisEz13) August 4, 2021 08:28
@iSazonov

Ilya (iSazonov) commented Aug 4, 2021

Copy link
Copy Markdown
Collaborator Author

Travis Plunk (@TravisEz13) Please review/approve.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost ghost removed the Review - Needed The PR is being reviewed label Aug 4, 2021
TravisEz13
Travis Plunk (TravisEz13) reviewed Aug 4, 2021
View reviewed changes
Comment thread ...osoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/HttpKnownHeaderNames.cs
if (s_contentHeaderSet == null)
{
s_contentHeaderSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
// Thread-safe initialization.

@TravisEz13 Travis Plunk (TravisEz13) Aug 4, 2021

Copy link
Copy Markdown
Member

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.

Suggested change
// Thread-safe initialization.
// Thread-safe initialization because the constructor is only called once per AppDomain.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
TravisEz13
Travis Plunk (TravisEz13) approved these changes Aug 4, 2021
View reviewed changes
@TravisEz13 Travis Plunk (TravisEz13) assigned Travis Plunk (TravisEz13) and unassigned Ilya (iSazonov) Aug 4, 2021
@TravisEz13 Travis Plunk (TravisEz13) changed the title Thread-safe HttpKnownHeaderNames initialization Thread-safe HttpKnownHeaderNames initialization Aug 4, 2021
@TravisEz13
Travis Plunk (TravisEz13) merged commit aaaa0f2 into PowerShell:master Aug 4, 2021
@iSazonov
Ilya (iSazonov) deleted the racecondition-in-httpknownheadernames branch August 5, 2021 02:52
@iSazonov Ilya (iSazonov) added this to the 7.2.0-preview.9 milestone Aug 5, 2021
@ghost

Deleted user (ghost) commented Aug 23, 2021

Copy link
Copy Markdown

🎉v7.2.0-preview.9 has been released which incorporates this pull request.:tada:

Handy links:

  • Release Notes
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost ghost mentioned this pull request Aug 23, 2021
Invoke-RestMethod parallel problem #15513
Closed
@ghost

Deleted user (ghost) commented Sep 28, 2021

Copy link
Copy Markdown

🎉v7.2.0-preview.10 has been released which incorporates this pull request.:tada:

Handy links:

  • Release Notes
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@iSazonov
Thread-safe HttpKnownHeaderNames initialization (PowerShell#15519)
73c4337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@TravisEz13 Travis Plunk (TravisEz13) TravisEz13 approved these changes
@daxian-dbw Dongbo Wang (daxian-dbw) Awaiting requested review from daxian-dbw
+2 more reviewers
@PaulHigin Paul Higinbotham (PaulHigin) PaulHigin approved these changes
@vexx32 Rain Sallow (/u/ta11ow) (vexx32) vexx32 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@TravisEz13 Travis Plunk (TravisEz13)

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Milestone

7.2.0-preview.9

Development

Successfully merging this pull request may close these issues.

Invoke-RestMethod parallel problem

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@iSazonov @vexx32 @dperez83 @TravisEz13 @PaulHigin
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.