-
Notifications
You must be signed in to change notification settings - Fork 364
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
AzureRM.* modules held in use by PSSA when Cluster 0.0.0.1 is scanned, prevents uninstall #841
Comments
Can you please post the exact error message? Does that happen even if you close PowerShell and try to uninstall in a new session? |
PS C:\windows\system32> Uninstall-Module -Name AzureRM.Websites -RequiredVersion 4.0.0
WARNING: The version '4.0.0' of module 'AzureRM.Websites' is currently in use. Retry the operation after closing the applications.
PackageManagement\Uninstall-Package : Module 'AzureRM.Websites' is in currently in use or you don't have the required permissions.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.6.0\PSModule.psm1:2459 char:21
+ ... $null = PackageManagement\Uninstall-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package], Exception
+ FullyQualifiedErrorId : ModuleIsInUse,Uninstall-Package,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage It succeeds if I close and open a new session. |
How is this related to PSSA? Guessing from the error message I'd say that you are not elevated (i.e. you need to launch PowerShell as an Administrator). |
When trying to repro, I can confirm that PackageManagement\Uninstall-Package : No match was found for the specified search criteria and module names 'AzureRM.Websites'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:2194 char:21
+ ... $null = PackageManagement\Uninstall-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage The repro steps were (with this custom rule being used) on a Win10 VM: Install-Module -Name Cluster -RequiredVersion 0.0.0.1 -Repository PSGallery
install-module psscriptanalyzer
ipmo PSScriptAnalyzer
Invoke-ScriptAnalyzer -Path 'C:\Program Files\WindowsPowerShell\Modules\cluster' -Recurse -Severity Error
Invoke-ScriptAnalyzer -Path 'C:\Program Files\WindowsPowerShell\Modules\cluster' -Recurse -Severity Error -CustomRulePath $PathToCustomRule
Uninstall-Module -Name Cluster -RequiredVersion 0.0.0.1
Uninstall-Module -Name AzureRM.Websites
get-module -ListAvailable AzureRM.Websites # check it is really still installed -> yes it is
Uninstall-Module -Name AzureRM.Websites # fails -> try other methods (fail as well)
Uninstall-Module -Name 'AzureRM.Websites'
get-module -ListAvailable AzureRM.Websites | uninstall-module
# dump info
$error[0] | select *
writeErrorStream : True
PSMessageDetails :
Exception : System.Exception: No match was found for the specified search criteria and module names 'AzureRM.Websites'.
TargetObject : Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
CategoryInfo : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package], Exception
FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Uninstall-Module<Process>, C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1: line 2194
at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.16299.98
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.98
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1 |
I was definitely running this as elevated. |
I tried to repro an a clean |
Yep, I've got PSSA 1.16.1 installed. |
I had a look a the |
I should clarify, I work on the PowerShell Gallery team. I implemented the prerelease versioning feature outlined in that blog post :) |
Haha, what a coincidence. Well in that case thanks for implementing this new feature. :-) |
You're welcome, hope you find it useful :-) |
A coworker talked with Kapil who used to work on PSSA. His findings:
|
@rebro-msft Sorry to revive an old thread, but we're seeing extreme slowness when analyzing script modules that are heavy on AzureRM cmdlets. Are you saying the issue stems from the @bergmeister We noticed a huge improvement in script analysis times (34+ minutes down to less than 3 minutes) for our module when uninstalling AzureRM from the build machine. But we're afraid that will mean we aren't getting good analysis coverage on commands it isn't able to find definitions for. Can you help me understand what we might lose in terms of script analysis quality if we decide to proceed with this workaround? Happy to open a separate issue if requested. |
@Blackbaud-ShaydeNofziger Although the tool is mostly static is consumes the local session to get more information about available commands, aliases or other custom definitions in the loaded session, various rules use the command/alias cache (around 5-10). Could you give an example so that I could repro your performance problem? The AzureRM module is known to be not the very best in terms of performance and will always be a bit of a bottleneck but half an hour is definitely too much. |
This is a very basic example but demonstrates what I mean - example.zip Below are my findings with our module in question. The times I was speaking of were from our build agent, but these results are from my laptop. Please note I am unable to share the codebase in a public forum. These tests were performed in brand new sessions without any Azure[RM] modules explicitly loaded With AzureRM Modules Installed C:\Repos\blackbaud-iaas-host-azure [master ≡]> Measure-Command { Invoke-ScriptAnalyzer -Path .\Blackbaud.Host.Azure\*.ps1 }
Days : 0
Hours : 0
Minutes : 13
Seconds : 32
Milliseconds : 269
Ticks : 8122691194
TotalDays : 0.00940126295601852
TotalHours : 0.225630310944444
TotalMinutes : 13.5378186566667
TotalSeconds : 812.2691194
TotalMilliseconds : 812269.1194 Without AzureRM Modules Installed C:\Repos\blackbaud-iaas-host-azure [master ≡]> Measure-Command { Invoke-ScriptAnalyzer -Path .\Blackbaud.Host.Azure\*.ps1 }
Days : 0
Hours : 0
Minutes : 0
Seconds : 24
Milliseconds : 388
Ticks : 243888910
TotalDays : 0.000282278831018518
TotalHours : 0.00677469194444444
TotalMinutes : 0.406481516666667
TotalSeconds : 24.388891
TotalMilliseconds : 24388.891 Would you like me to open a separate issue? |
Thanks, I will take a look at it in the next days with your example and depending on the outcome we can then open a more specific issue (or multiple) once we have more information. |
The codebase only includes calls to the AzureRM cmdlets, and the AzureRM roll-up module is listed as a Script Analyzer is only scanning our My example is admittedly basic. But any script that includes several different calls to the AzureRM cmdlets sees a significant increase in analysis time. |
@Blackbaud-ShaydeNofziger OK, I ran a quick test with your example, and running an |
@bergmeister Thank you so much for the info! I can confirm that re-running analysis after the initial run does speed things up a ton, so I agree it sounds like the it's the initial caching/JITTING process - Thanks for the tip about building in VS to see the performance. I'll look into that this weekend.
Do you have the Azure SDK installed? I think that install path is a default module location, so PS falls back to those DLL's if it can't find the modules installed from psgallery. I like your recommendation about the nightly builds - it gives us the speed we need during the day without sacrificing deeper analysis, which we can run overnight. I appreciate you looking into this for me and giving some insight into what's happening under the hood. Example results from re-running in the same session: C:\Repos\blackbaud-iaas-host-azure [master ≡]> Measure-Command { Invoke-ScriptAnalyzer -Path .\Blackbaud.Host.Azure\ApplicationGateway.ps1 }
Days : 0
Hours : 0
Minutes : 1
Seconds : 9
Milliseconds : 255
Ticks : 692551851
TotalDays : 0.000801564642361111
TotalHours : 0.0192375514166667
TotalMinutes : 1.154253085
TotalSeconds : 69.2551851
TotalMilliseconds : 69255.1851
C:\Repos\blackbaud-iaas-host-azure [master ≡]> Measure-Command { Invoke-ScriptAnalyzer -Path .\Blackbaud.Host.Azure\ApplicationGateway.ps1 }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 29
Ticks : 299614
TotalDays : 3.46775462962963E-07
TotalHours : 8.32261111111111E-06
TotalMinutes : 0.000499356666666667
TotalSeconds : 0.0299614
TotalMilliseconds : 29.9614 |
@Blackbaud-ShaydeNofziger No, I don't have the Azure SDK installed but I noticed that when I uninstalled |
@bergmeister I have a task to address all of this in next week's sprint - The information you've provided so far has been super-helpful, and I made some good progress building PSSA locally and measuring performance in VS. I'll dive deep into this next week and will be able to provide my findings so far, with a more comprehensive example. I'll open a separate issue at that time (referencing this one) with the details above and more information, as I think it could prove helpful to others that may be experiencing performance issues. In the end, if it seems appropriate, I'd like to turn all of this and the information you provided into a documentation-contribution to help others better understand how PSScriptAnalyzer runs under the hood, as well as tips for addressing performance issues. Do you think that would be a worthwhile contribution? |
We always welcome contributions. A brief description, especially from a user's point of view about performance would be valuable. The thing about implementation details is that they are likely to go out of date but a high level description would still be good. |
Repro steps
Expected Behavior
I should be able to uninstall the AzureRM.* modules. I don't expect PSSA to hold on to them.
We are unable to uninstall any of the AzureRM.* modules because something in PSSA is holding on to them. This appears to only happen for the Cluster 0.0.0.1 module.
The text was updated successfully, but these errors were encountered: