Skip to content

[release/v7.4] Fix the NREs when writing to console from multiple threads - #25503

Closed
PowerShell Team Bot (pwshBot) wants to merge 1 commit into
PowerShell:release/v7.4from
pwshBot:backport/release/v7.4/25440-9a6a63820
Closed

[release/v7.4] Fix the NREs when writing to console from multiple threads#25503
PowerShell Team Bot (pwshBot) wants to merge 1 commit into
PowerShell:release/v7.4from
pwshBot:backport/release/v7.4/25440-9a6a63820

Conversation

@pwshBot

@pwshBot PowerShell Team Bot (pwshBot) commented May 3, 2025

Copy link
Copy Markdown
Collaborator

Backport of #25440 to release/v7.4

Triggered by Travis Plunk (@TravisEz13) on behalf of Kris Borowinski (@kborowinski)

Original CL Label: CL-General

/cc @PowerShell/powershell-maintainers

Impact

Choose either tooling or Customer impact.

Tooling Impact

  • Required tooling change
  • Optional tooling change (include reasoning)

Customer Impact

  • Customer reported
  • Found internally

Comment from Kris Borowinski (@kborowinski)

#25440 (comment)

I understand the decision not to backport this PR to the LTS version, but I would like to clarify that the actual script results are affected in PS 7.4.X and up.

I first reported this issue on the 7Zip4PowerShell repo, where the unpacking process was crashing mid-task.
I proposed a PR that was merged to implement a workaround that swallows NREs coming from progress pane:

try {
    worker.Progress.StatusDescription = "Finished";
    worker.Progress.RecordType = ProgressRecordType.Completed;
    WriteProgress(worker.Progress);
} catch (NullReferenceException) {
    // Possible bug in PowerShell 7.4.0 leading to a null reference exception being thrown on ProgressPane completion
    // This is not happening on PowerShell 5.1
}

This issue affects all scripts that write to the console from multiple threads, leading to potential crashes in the LTS version of PowerShell. Affected users are forced to disable the progress bar either globally or per script.

Regression

  • Yes
  • No

[If yes, specify when the regression was introduced. Provide the PR or commit if known.]

Testing

[How was the fix verified? How was the issue missed previously? What tests were added?]

Risk

  • High
  • Medium
  • Low

[High/Medium/Low. Justify the indication by mentioning how risks were measured and addressed.]

…l#25440)

The WriteImpl() method should always be called within a lock on _instanceLock to ensure thread safety.
@TravisEz13 Travis Plunk (TravisEz13) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label May 4, 2025
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label May 11, 2025
@TravisEz13

Copy link
Copy Markdown
Member

@PowerShell/powershell-maintainers Behavioral stability is paramount for LTS releases. We don't believe this meets the bar for an LTS release as it causes significant changes to how the console functions.

@microsoft-github-policy-service

microsoft-github-policy-service Bot commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

📣 Hey @PowerShell Team Bot (@pwshBot), how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants