KEMBAR78
Allow opt-out of the named-pipe listener using an environment variable by daxian-dbw · Pull Request #26086 · PowerShell/PowerShell · GitHub
Skip to content

Conversation

@daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Sep 23, 2025

PR Summary

Fix #11599

The named-pipe listener is created for all PowerShell instances today (including scenarios where apps host PowerShell). On Linux platforms, this causes the named pipe files left behind uncleaned when PowerShell terminates abruptly.

This PR includes changes to allow opt-out of the named-pipe listener using the environment variable POWERSHELL_DIAGNOSTICS_OPTOUT.

For reference, .NET has the environment variable DOTNET_EnableDiagnostics for disabling the debugger, the profiler, and EventPipe diagnostics (enabled by default).

PR Checklist

@daxian-dbw daxian-dbw added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Sep 23, 2025
@daxian-dbw daxian-dbw marked this pull request as ready for review September 23, 2025 21:45

var boolStr = str.AsSpan();

if (boolStr.Length == 1)
Copy link
Collaborator

@jborean93 jborean93 Sep 23, 2025

Choose a reason for hiding this comment

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

Could you possibly use SequenceEqual possibly with or without StringComparer.OrdinalIgnoreCase to avoid the individual length and char checks. I assume .NET has all the necessary logic to make that performant and you could make this a lot simpler by doing something like

ReadOnlySpan<char> true1 = ['1'];
ReadOnlySpan<char> trueYes = ['y', 'e', 's'];
ReadOnlySpan<char> trueTrue = ['t', 'r', 'u', 'e'];

// Repeat for false checks

var boolStr = str.AsSpan()
if (boolStr.SequenceEquals(true1, StringComparer.OrdinalIgnoreCase) ||
    boolStr.SequenceEquals(trueYes, StringComparer.OrdinalIgnoreCase ||
    ...)
{
    return true;
}

// Repeat for false checks and default
...

Not sure if stackalloc'ing one big span with all the options and slicing it would be more efficient or not but that's probably in micro-optimising territory.

Edit: Ah I see this has been copied from elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is copied from Telemetry.cs. I will keep it as is in this PR as this one will be included in the next preview and the following RC. But I will submit a separate PR to make this optimization change.

@iSazonov
Copy link
Collaborator

/azp run PowerShell-Windows-Packaging-CI, PowerShell-CI-linux-packaging

@azure-pipelines
Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@daxian-dbw
Copy link
Member Author

@iSazonov I guess you clicked the "Update branch" button. There were unrelated test failures after merging the master branch, so I have to revert that (force pushed the original 2 commits again). Please approve again once all CIs pass, thank you!

@iSazonov
Copy link
Collaborator

Oh, sorry! It seems the button is too near to scroll bar.

I restarted CIs and the WindowStyle test fail again. :-(

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM!

@daxian-dbw
Copy link
Member Author

/azp run PowerShell-CI-linux-packaging, PowerShell-Windows-Packaging-CI

@azure-pipelines
Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@daxian-dbw
Copy link
Member Author

daxian-dbw commented Sep 30, 2025

The failing tests are as following. They are not related to the changes and consistently fail for all CIs starting from 9/26.
I will merge the PR regardless of those 3 failures.

  Describing WindowStyle argument
    [-] -WindowStyle Normal should work on Windows
      Expected exactly 'Normal', but got Hidden.
      1044:             $showCmd | Should -BeExactly $WindowStyle
      at <ScriptBlock>, D:\a\PowerShell\PowerShell\test\powershell\Host\ConsoleHost.Tests.ps1: line 1044
    [-] -WindowStyle Minimized should work on Windows
      Expected exactly 'Minimized', but got Hidden.
      1044:             $showCmd | Should -BeExactly $WindowStyle
      at <ScriptBlock>, D:\a\PowerShell\PowerShell\test\powershell\Host\ConsoleHost.Tests.ps1: line 1044
    [-] -WindowStyle Maximized should work on Windows
      Expected exactly 'Maximized', but got Hidden.
      1044:             $showCmd | Should -BeExactly $WindowStyle
      at <ScriptBlock>, D:\a\PowerShell\PowerShell\test\powershell\Host\ConsoleHost.Tests.ps1: line 1044

[UPDATE] I cannot bypass the policy to merge the PR with failing tests. The 3 tests are disabled now in master branch, and I will rebase the PR against the master branch.

@daxian-dbw
Copy link
Member Author

/azp run PowerShell-CI-linux-packaging, PowerShell-Windows-Packaging-CI

@azure-pipelines
Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@daxian-dbw daxian-dbw merged commit 859431e into PowerShell:master Sep 30, 2025
36 checks passed
@daxian-dbw daxian-dbw deleted the diag_optout branch September 30, 2025 19:56
@iSazonov
Copy link
Collaborator

iSazonov commented Oct 1, 2025

Should the new env variable be documented?

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

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

running ps1 script create temp file in everytime

6 participants