Close

Floating PWSH instance

A project log for Source Code Analysis: PowerShellEditorServices

Source Code Breakdown of PowerShellEditorServices (at the time of v3.5.4)

nicholas-jacksonNicholas Jackson 10/13/2022 at 22:020 Comments

When running the initializer script, it runs it in a secondary pwsh instance to prevent the main script from hanging. However, you can't fully kill it from the parent process, because the second script spawns a third mystery powershell instance that doesn't die when you kill the second one... Gotta find a work around to prevent leaks in my scripts :(

Finding the Cause:

Couldn't find it at the moment. Trying to increase logging verbosity.

Here are the valid values for loglevel:

https://github.com/PowerShell/PowerShellEditorServices/blob/8e92d8ee7c5d382b1fa0ea143a5dd1d3fe838d80/module/PowerShellEditorServices/Start-EditorServices.ps1#L52

It is also possible that the only way to shutdown the app is via LSP message

Running this code from stackoverflow to get child PIDs of the second powershell instance reveals the PID of the third one, but also reveals that it also spawned a conhost instance.

Gonna try using this process tree killer to kill the server:

https://stackoverflow.com/questions/55896492/terminate-process-tree-in-powershell-given-a-process-id

Ha, ha, ha... lol I'm an idiot

My script starting the Editor Services is another call to pwsh. I'm an idiot.

Also, fun fact. This was staring me in the face the whole time:

Discussions