Skip to content

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

Merged
iSazonov merged 44 commits intoPowerShell:masterfrom
TylerLeonhardt:debugpipename-enterpshostprocess
Feb 22, 2019
Merged

[feature] Add -CustomPipeName to pwsh and Enter-PSHostProcess#8889
iSazonov merged 44 commits intoPowerShell:masterfrom
TylerLeonhardt:debugpipename-enterpshostprocess

Conversation

@TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Feb 13, 2019

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
Contributor

@PaulHigin PaulHigin left a comment

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
Contributor

@PaulHigin PaulHigin left a comment

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
Copy link
Member Author

TylerLeonhardt commented Feb 15, 2019

@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
Member Author

Addressed all feedback 👍

Copy link
Contributor

@PaulHigin PaulHigin left a comment

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
Member Author

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

@TylerLeonhardt
Copy link
Member Author

I've addressed @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
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.

Copy link
Member Author

@TylerLeonhardt TylerLeonhardt Feb 21, 2019

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
Collaborator

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

@TylerLeonhardt
Copy link
Member Author

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

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

LGTM with minor comments.

@iSazonov 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
Collaborator

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

@TylerLeonhardt
Copy link
Member Author

Done, @iSazonov!

@iSazonov iSazonov self-assigned this Feb 22, 2019
@iSazonov iSazonov merged commit 23eccfd into PowerShell:master Feb 22, 2019
@iSazonov
Copy link
Collaborator

@TylerLeonhardt Thanks for your contribution!

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