Closed LaurentDardenne closed 10 months ago
Looks like the old CommandInfo
off the pipeline thread race condition
We could apply something similar to PR #1523
The problem I see is that taking a CommandInfo
object and accessing it off the original pipeline thread is always going to have this race condition. Even falling through the cache still presents the possibility of a race condition. The only safe way to manipulate these objects is to leave the pipeline on a dedicated thread and run delegates on it that copy the needed values over. I'm currently building something like this for PSES for other reasons, but it's not infeasible. Honestly though, this is a big reason why I think depending on PowerShell for linting here is an issue
Thanks @LaurentDardenne could you please to run only the PSSA command line when you have the chance and let us know if you are able to reproduce this?
Looks like the issue may be coming from PowerShell here, still, PSSA should protect itself from these types of errors/better handle parameter binding especially since we expect PSSA to be backwards compatible...we may want to check for a throw as well here, alternatively this rule could not use the helper function at all
Hi,
I think I am having a very similar issue.
When analyzing PSShouldProcess, I get the Object reference not set to an instance of an object.
Exception :
@{Exception=System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.TryGetShouldProcessValueFromAst(FunctionInfo functionInfo, Boolean& hasShouldProcessSet)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.SupportsShouldProcess(String cmdName)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.CheckForSupportShouldProcess()
at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.<AnalyzeScript>d__7.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass83_1.<AnalyzeSyntaxTree>b__2()}
I had no problem yesterday, but today, analyzing doesn't work.
I found that it is specifically the PSShouldProcess rule that makes it not work. If excluded, it pass.
None of my function uses ShouldProcess.
Environment : Windows 10 2004, PS 5.1
Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.0.11 BuildHelpers {Add-TestResultToAppveyor, Export-Metadata, Find-NugetPackage, Get-BuildEnvironment...}
Script 1.3.1 Configuration {Add-MetadataConverter, ConvertFrom-Metadata, ConvertTo-Metadata, Export-Configuration...}
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest 3.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
Script 0.14.0 platyPS {Get-HelpPreview, Get-MarkdownMetadata, Merge-MarkdownHelp, New-ExternalHelp...}
Script 0.4.0 PowerShellBuild {Build-PSBuildMAMLHelp, Build-PSBuildMarkdown, Build-PSBuildModule, Build-PSBuildUpdatableHelp...}
Script 0.2.0 PowerShellEditorServices.Commands {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-ScriptExtent, Find-Ast...}
Binary 0.2.0 PowerShellEditorServices.VSCode {Close-VSCodeHtmlContentView, New-VSCodeHtmlContentView, Set-VSCodeHtmlContentView, Show-VSCodeHtmlContentView...}
Script 4.8.0 psake {Assert, Exec, FormatTaskName, Framework...}
Script 2.0.2 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}
Script 1.19.0 PSScriptAnalyzer {Get-ScriptAnalyzerRule, Invoke-Formatter, Invoke-ScriptAnalyzer}
By the tag 'Consider 2.0', do you mean I should try 2.0 ? Since it is not on the PSGallery yet, how should I install it ? Thanks
@avezinaATastus that looks like a different issue in this method:
Please open a new issue
@SydneyhSmith
Thanks @LaurentDardenne could you please to run only the PSSA command line when you have the chance and let us know if you are able to reproduce this?
Yes I can, but not before a few weeks.
By the tag 'Consider 2.0', do you mean I should try 2.0 ? Since it is not on the PSGallery yet, how should I install it ?
That tag means we're considering addressing this issue in the 2.0 version, which is still being worked on.
@SydneyhSmith My code having evolved, it no longer causes an error via psake or on the command line. The only thing that differs on the first run is the scan time, but that's unrelated.
First run
--------------------------------------------------
Build Time Report
--------------------------------------------------
Name Duration
---- --------
Init 00:00:00.033
Clean 00:00:00.073
BeforeBuild 00:00:00.001
RemoveConditionnal 00:00:00.000
BeforeStageFiles 00:00:00.001
CoreStageFiles 00:00:00.292
TestBOM 00:00:05.819
TestLocalizedData 00:00:00.000
AfterStageFiles 00:00:00.001
StageFiles 00:00:00.001
Analyze 00:00:40.536 <-------
TestBOMAfterAll 00:00:09.232
AfterBuild 00:00:00.007
Build 00:00:00.001
Total: 00:00:56.163
Next :
-----------------------------------
Build Time Report
-----------------------------------
Name Duration
---- --------
Init 00:00:00.003
Clean 00:00:00.159
BeforeBuild 00:00:00.002
RemoveConditionnal 00:00:00.000
BeforeStageFiles 00:00:00.001
CoreStageFiles 00:00:00.137
TestBOM 00:00:07.524
TestLocalizedData 00:00:00.000
AfterStageFiles 00:00:00.001
StageFiles 00:00:00.001
Analyze 00:00:01.004 <------
TestBOMAfterAll 00:00:14.883
AfterBuild 00:00:00.004
Build 00:00:00.001
Total: 00:00:23.749
The module was not installed via Install-Module but downloaded from the PS Gallery + 'XCopy'.
I have this bug in 1.22.0. Does anybody know what magical trick can be done to avoid it? It may be that, like OP, I have installed PSScriptAnalyzer in a local directory instead of just install-module and letting module-search handle it.
I report this error although I cannot reproduce the bug, moreover the analyzed code is private :-/
The exception is random during a build via PSake. I already had this error with the previous version 1.8. The exception is most often raised when I open a powershell session and then execute my build script. When, after the triggering of the error, I relaunch my error script, I no longer have an error
I have not yet had time to run only the PSSA command line.
Actual behavior
The first three lines are always the same :
The fourth concerns a rule name which can be different :
The TargetObject property points to a module of the project. The module may not have been modified for several days and may not trigger an error during the previous analysis (10 minutes ago)
Environment data
Test without any error, performed after the error is triggered :
Command line :