Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-ScriptAnalyzer keeps powershell_ise process open #1416

Open
gpetrou opened this issue Feb 17, 2020 · 3 comments
Open

Invoke-ScriptAnalyzer keeps powershell_ise process open #1416

gpetrou opened this issue Feb 17, 2020 · 3 comments

Comments

@gpetrou
Copy link

gpetrou commented Feb 17, 2020

Steps to reproduce

Use the following code in PowerShell ISE:
Import-Module "PATH_TO\psscriptanalyzer\1.18.3\PSScriptAnalyzer.psm1"
Invoke-ScriptAnalyzer "PATH_TO\Dummy.psm1"
Dummy just has a:
function DummyFunction() {}
Close the PowerShell ISE.

Expected behavior

The powershell_ise process terminates.

Actual behavior

The powershell_ise process stays open.

Environment data

PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

PSScriptAnalyzer Version 1.18.3

@bergmeister
Copy link
Collaborator

bergmeister commented Feb 17, 2020

I can confirm, a simpler repro is to just execute Invoke-ScriptAnalyzer -ScriptDefiniton 'foo'.
@gpetrou Can you please describe the impact and severity of this to you?

Investigation: I tried different versions of PSSA and it seems this behaviour started first in 1.18.1 (i.e. the bug is not present in 1.18.0). We (the maintainers, i.e. Jim, Rob and myself) know that there is a few singletons in there for the command cache, therefore my suspicion is that there are pinned objects that make .Net decide to block the process from stopping. By looking at the changes, it is probably most likely that the culprit might be PR #1178, which introduced the caching of a runspace pool (which was an important performance tweak as it halved the time to analyse for cold runs).
This behaviour does not apply to the process of VS-Code or conhost.exe (which is hosting powershell.exe/pwsh.exe) therefore I am also thinking that some sort of blame could also go to the ISE. @SydneyhSmith Can you ask the team for feedback on what they think about this (i.e. should we even aim to fix this given that the ISE is considered legacy, of course assuming that the impact of this bug is low)?

@gpetrou
Copy link
Author

gpetrou commented Feb 17, 2020

I use the ISE when developing scripts and it is annoying having to manually kill the process.
I guess I should switch to VS-Code :)
Is there a command I could perhaps run before the script finishes to release objects that are still used?

@bergmeister
Copy link
Collaborator

@gpetrou Yes, switching to VS-Code would help, this guide should help you: https://docs.microsoft.com/en-us/powershell/scripting/components/vscode/how-to-replicate-the-ise-experience-in-vscode?view=powershell-7
But coming back to my question: What problems does the left-over process cause to you in terms of impact? The process by itself should not harm you and the memory footprint shouldn't be big unless you load a lot of data into memory. You can technically run [gc]::Collect() but it does not help in this case.

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

No branches or pull requests

2 participants