Skip to content

[feature] Add -CustomPipeName to pwsh and Enter-PSHostProcess - #8889

Merged
Ilya (iSazonov) merged 44 commits into
PowerShell:masterfrom
TylerLeonhardt:debugpipename-enterpshostprocess
Feb 22, 2019
Merged

Ilya (iSazonov) merged 44 commits into
PowerShell:masterfrom
TylerLeonhardt:debugpipename-enterpshostprocess

Conversation

@TylerLeonhardt

@TylerLeonhardt TylerLeonhardt commented Feb 13, 2019 •

Copy link
Copy Markdown
Member

PR Summary

This allows a user to start PowerShell up with the name of the named pipe that is used for cross process communication (I.e. Enter-PSHostProcess).

Example:

terminal 1

pwsh -custompipename mypipe

terminal 2

Enter-PSHostProcess -CustomPipeName mypipe

PR Context

Today, it is impossible to predictively connect to a PowerShell process without knowing its process id. If you're stopping and starting a powershell process often... you have no mechanism for figuring out the process id.

This introduces a consistent way to connect to a PowerShell process by specifying the NamedPipe yourself.

This is very nice in PowerShell hosted scenarios - for example, in Azure Functions where PowerShell is hosted. This enables the ability to consistently connect to the PowerShell instance hosted there without any additional information besides the CustomPipeName that can be reused.

This feature also means that in the PowerShell extension for VSCode, we can achieve "Attach to Process" debugging with a single stroke of the F5 key.

PR Checklist

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I will finish the review later, but have a couple of comments now.
Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's remove the connection of pipe listener creation to local runspace, and think about whether we want to replace the existing default IPC channel or create a second one when starting powershell.exe in DebugPipeName mode, although I think we should use a different name for the switch, like IPCPipe or CustomIPCPipe, or something.

@TylerLeonhardt TylerLeonhardt changed the title [feature] Add -DebugPipeName to pwsh and Enter-PSHostProcess [feature] [WIP] Add -DebugPipeName to pwsh and Enter-PSHostProcess Feb 15, 2019
@TylerLeonhardt

TylerLeonhardt commented Feb 15, 2019 •

Copy link
Copy Markdown
Member Author

Paul Higinbotham (@PaulHigin) I've refactored this quite a bit based on your offline feedback. The same experience is there for a user at the CLI.

For users that are going through the API, the can use:

S.M.A.Remoting.RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer("mypipe");

There is 1 thing left to do here:

  • change the name from DebugPipeName to CustomPipeName - everyone feel free to comment changed

  • figure out what should happen when this static function is called multiple times - Should it throw? Or should it overwrite? I've added it to dispose of the current server and recreate the new one

@TylerLeonhardt
TylerLeonhardt force-pushed the debugpipename-enterpshostprocess branch from d47a632 to d7df174 Compare February 15, 2019 23:55
@TylerLeonhardt TylerLeonhardt changed the title [feature] [WIP] Add -DebugPipeName to pwsh and Enter-PSHostProcess [feature] Add -DebugPipeName to pwsh and Enter-PSHostProcess Feb 16, 2019
@TylerLeonhardt

Copy link
Copy Markdown
Member Author

Addressed all feedback 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. But please create new Issue about disposing pipe server objects on process exit (please see comment).

@TylerLeonhardt

Copy link
Copy Markdown
Member Author

Ok I included a few CodeFactor and Codacy fixes as well. This should be good to go pending CI ✅

@TylerLeonhardt

Copy link
Copy Markdown
Member Author

I've addressed Paul Higinbotham (@PaulHigin)'s final point which is that DebugPipeName is not totally accurate as this pipe could be used for other IPC scenarios.

It's mostly used for debugging though... and our usecase is really for debugging... so I've called this out in the -help page.

His recommendation and what I went with was CustomPipeName. I've updated that throughout.

@TylerLeonhardt TylerLeonhardt changed the title [feature] Add -DebugPipeName to pwsh and Enter-PSHostProcess [feature] Add -CustomPipeName to pwsh and Enter-PSHostProcess Feb 21, 2019
case ProcessIdParameterSet:
Process = GetProcessById(Id);
VerifyProcess(Process);
namedPipeRunspace = CreateNamedPipeRunspace(Process.Id, AppDomainName);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Interesting, do we really need the VerifyProcess() check (that is File.Exist())? Perhaps the runtime error is informative enough.

@TylerLeonhardt TylerLeonhardt Feb 21, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not quite sure what you're saying. This VerifyProcess is to keep the behavior consistent with the current behavior for Process parameter sets.

@iSazonov

Copy link
Copy Markdown
Collaborator

TylerLeonhardt Please create new Issue in PowerShell-Docs repo and add reference to the PR description.

@TylerLeonhardt

Copy link
Copy Markdown
Member Author

Alright CI is green and codacy and Code Factor are mostly happy. This should be good to go.

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM with minor comments.

Comment thread test/xUnit/csharp/test_NamedPipe.cs Resolved
Comment thread test/xUnit/csharp/test_NamedPipe.cs Resolved
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Feb 22, 2019
@iSazonov

Copy link
Copy Markdown
Collaborator

TylerLeonhardt Please create new Issue in PowerShell-Docs repo before we merge.

@TylerLeonhardt

Copy link
Copy Markdown
Member Author

Done, Ilya (@iSazonov)!

@iSazonov Ilya (iSazonov) self-assigned this Feb 22, 2019
@iSazonov
Ilya (iSazonov) merged commit 23eccfd into PowerShell:master Feb 22, 2019
@iSazonov

Copy link
Copy Markdown
Collaborator

TylerLeonhardt Thanks for your contribution!

@TylerLeonhardt
TylerLeonhardt deleted the debugpipename-enterpshostprocess branch February 23, 2019 01:35
@joeyaiello Joey Aiello (joeyaiello) added this to the 6.2.0 milestone Mar 22, 2019
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…werShell#8889)

This allows a user to start PowerShell up with the name of the named pipe that is used for cross process communication (I.e. Enter-PSHostProcess).
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.

6 participants