Skip to content

Remove eager initialization of _startupScripts to enable lazy thread-safe initialization#25767

Merged
daxian-dbw merged 1 commit into
PowerShell:masterfrom
xtqqczze:StartupScripts
May 11, 2026
Merged

Remove eager initialization of _startupScripts to enable lazy thread-safe initialization#25767
daxian-dbw merged 1 commit into
PowerShell:masterfrom
xtqqczze:StartupScripts

Conversation

@xtqqczze
Copy link
Copy Markdown
Contributor

@xtqqczze xtqqczze commented Jul 20, 2025

The field _startupScripts was being initialized at declaration, which prevented the
Interlocked.CompareExchange logic in the StartupScripts property from ever executing.

This change removes the eager initialization to allow proper lazy and thread-safe setup
of the HashSet when the property is first accessed.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Jul 27, 2025
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

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

…d-safe initialization

The field `_startupScripts` was being initialized at declaration, which prevented the
`Interlocked.CompareExchange` logic in the `StartupScripts` property from ever executing.
This change removes the eager initialization to allow proper lazy and thread-safe setup
of the HashSet when the property is first accessed.
@xtqqczze xtqqczze requested a review from a team as a code owner February 19, 2026 17:54
Comment thread src/System.Management.Automation/engine/InitialSessionState.cs
@iSazonov iSazonov added CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log Resolution-Declined The proposed feature is declined. labels Feb 20, 2026
@xtqqczze xtqqczze requested a review from iSazonov March 17, 2026 15:28
@daxian-dbw daxian-dbw removed the Resolution-Declined The proposed feature is declined. label May 6, 2026
@daxian-dbw
Copy link
Copy Markdown
Member

@xtqqczze Can you please revert the 2nd commit? I think only the 1st commit will do the trick. Thanks!

@daxian-dbw daxian-dbw removed the Review - Needed The PR is being reviewed label May 6, 2026
Copilot AI review requested due to automatic review settings May 6, 2026 21:12
@xtqqczze xtqqczze requested a review from daxian-dbw May 6, 2026 21:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR fixes lazy, thread-safe initialization of StartupScripts by removing eager initialization of the backing field so the Interlocked.CompareExchange path can execute as intended.

Changes:

  • Removed inline initialization of _startupScripts so the StartupScripts property can lazily initialize it on first access.

Comment thread src/System.Management.Automation/engine/InitialSessionState.cs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/System.Management.Automation/engine/InitialSessionState.cs
Copy link
Copy Markdown
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @xtqqczze!

@daxian-dbw
Copy link
Copy Markdown
Member

The CodeQL Analysis task got skipped due to a change of the task:

Warning: Starting April 2026, the CodeQL Action will skip computing file coverage information on pull requests to improve analysis performance. File coverage information will still be computed on non-PR analyses.

It's not related to this PR, so I will merge it.

@daxian-dbw daxian-dbw merged commit 146c046 into PowerShell:master May 11, 2026
39 of 43 checks passed
@xtqqczze xtqqczze deleted the StartupScripts branch May 11, 2026 19:03
JustinGrote pushed a commit to JustinGrote/PowerShell that referenced this pull request Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants