Repository navigation
Process is terminating due to StackOverflowException with custom provider on PSModulePath #5565
Description
Activity
- addedWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the product
on Nov 28, 2017 This repros in Windows PowerShell 5.1 so it's not due to any changes we've made in PSCore6
My hypothesis is that the VSTeam module calls into SHiPs module which in turn calls VSTeam module, etc... until stack runs out. cc Jianyun (@jianyunt)
I was able to replicate the error in 5.1 as well. Donovan Brown (@DarqueWarrior) we never tested with the module on psmodulepath with Windows 5.1 - only loading from off psmodulepath.
Something is "wrong" in the steps below so I cannot repro it?
cd E:\azure git clone https://github.com/DarqueWarrior/vsteam.git PS E:\azure> install-module ships PS E:\azure> cd E:\azure\vsteam PS E:\azure\vsteam> ipmo ships PS E:\azure\vsteam> $path="e:\azure" PS E:\azure\vsteam> $((resolve-path $path).path) E:\azure PS E:\azure\vsteam> $env:PSModulePath += ";$((resolve-path $path).path)" PS E:\azure\vsteam> $env:PSModulePath C:\Users\jianyunt\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;C:\Progr m Files (x86)\Microsoft Azure Information Protection\Powershell;E:\azure PS E:\azure\vsteam> Import-module vsteam PS E:\azure\vsteam> gmo vsteam | fl Name : vsteam Path : E:\azure\vsteam\vsteam.psd1 Description : Adds functionality for working with Visual Studio Team Services and Team Foundation Server. ModuleType : Manifest Version : 2.0.0 NestedModules : {team, git, Approvals, buildDefinitions...} ExportedFunctions : {Add-VSTeam, Add-VSTeamAccount, Add-VSTeamAzureRMServiceEndpoint, Add-VSTeamBuild...} ExportedCmdlets : ExportedVariables : VSTeamVersionTable ExportedAliases : {Add-AzureRMServiceEndpoint, Add-Build, Add-BuildDefinition, Add-BuildTag...} PS E:\azure\vsteam> New-PSDrive -Name vs -PSProvider SHiPS -Root 'VSTeam#VSAccount' -Scope Global -verbose VERBOSE: Performing the operation "New drive" on target "Name: vs Provider: Microsoft.PowerShell.SHiPS\SHiPS Root: VSTeam#VSAccount". VERBOSE: import-module VSTeam; get-module VSTeam -verbose VERBOSE: E:\azure\vsteam\vsteam.psd1 VERBOSE: using module 'E:\azure\vsteam\vsteam.psd1'; $mod=get-module VSTeam; &($mod){[VSAccount]::new('VSAccount')} Name Used (GB) Free (GB) Provider Root CurrentLocation ---- --------- --------- -------- ---- --------------- vs SHiPS VSTeam#VSAccount
We have related Issue with discussions about reloading nested modules. #2505
Jianyun (@jianyunt) it doesn't repro if you call
new-psdriveoutside of the module. it only overflows ifnew-psdriveis called within the module:add-teamaccount -account foo -personal bar -drive vs
DarqueWarrior commented
on Nov 29, 2017 ContributorAuthorMore actionsThe goal was to offer a much easier way to add a drive using the -Drive parameter. As Steve Lee (@SteveL-MSFT) explained if called separately it works fine. I never remember how to call New-PSDrive and have to look it up so I wanted to save the users of VSTeam from the same issue by simply doing it for them with -Drive.
The part that confuses me is the fact that if the module is not on PSModulePath everything works but if it is it breaks.It looks like there is a circular dependency in handling nestedmodudule (VSTeam=>Team=>VSTeam) if the module path is in the psmodulepath. The problem has been there in Windows PowerShell too.
Details:
The infinite loop is in the GetExportedTypeDefinitions. While new-psdrive, the SHiPS calls “import-module VSTeam; get-module VSTeam” via the PowerShellprovider.SessionState.InvokeCommand.InvokeScript().
Here is my findings about why loading vsteam module from local path works but it does not if under psmodulepath.-
Import-module vsteam from a local path. This case works fine. From my watch window, you can see VSTeam has a nestedmodule, Team but it has no nestedmodules.

-
While VSTeam module is in the psmodulepath, from the debugger you can see
VSteamhas NestedModule,Team, which a nestedmodule,VSTeam, which is causing module loading infinitely.

Stack System.Management.Automation.dll!System.Management.Automation.PSModuleInfo.GetExportedTypeDefinitions() Line 580 (e:\powershell\src\System.Management.Automation\engine\Modules\PSModuleInfo.cs:580) System.Management.Automation.dll!System.Management.Automation.AnalysisCache.CacheModuleExports(System.Management.Automation.PSModuleInfo module, System.Management.Automation.ExecutionContext context) Line 465 (e:\powershell\src\System.Management.Automation\engine\Modules\AnalysisCache.cs:465) System.Management.Automation.dll!Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingModulePath(System.Management.Automation.PSModuleInfo parentModule, bool found, System.Collections.Generic.IEnumerable<string> modulePath, string name, System.Management.Automation.SessionState ss, Microsoft.PowerShell.Commands.ModuleCmdletBase.ImportModuleOptions options, Microsoft.PowerShell.Commands.ModuleCmdletBase.ManifestProcessingFlags manifestProcessingFlags, out System.Management.Automation.PSModuleInfo module) Line 345 (e:\powershell\src\System.Management.Automation\engine\Modules\ModuleCmdletBase.cs:345) System.Management.Automation.dll!Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingModulePath(bool found, System.Collections.Generic.IEnumerable<string> modulePath, string name, System.Management.Automation.SessionState ss, Microsoft.PowerShell.Commands.ModuleCmdletBase.ImportModuleOptions options, Microsoft.PowerShell.Commands.ModuleCmdletBase.ManifestProcessingFlags manifestProcessingFlags, out System.Management.Automation.PSModuleInfo module) Line 276 (e:\powershell\src\System.Management.Automation\engine\Modules\ModuleCmdletBase.cs:276) System.Management.Automation.dll!Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(Microsoft.PowerShell.Commands.ModuleCmdletBase.ImportModuleOptions importModuleOptions, string name) Line 708 (e:\powershell\src\System.Management.Automation\engine\Modules\ImportModuleCommand.cs:708) System.Management.Automation.dll!Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord() Line 1731 (e:\powershell\src\System.Management.Automation\engine\Modules\ImportModuleCommand.cs:1731) System.Management.Automation.dll!System.Management.Automation.Cmdlet.DoProcessRecord() Line 177 (e:\powershell\src\System.Management.Automation\engine\cmdlet.cs:177) System.Management.Automation.dll!System.Management.Automation.CommandProcessor.ProcessRecord() Line 360
Repro steps
cd E:\azure\vsteam Import-module SHipS $path="e:\azure" $((resolve-path $path).path) $env:PSModulePath += ";$((resolve-path $path).path)" Import-module VSTeam -verbose $secure=convertTo-SecureString "htbaixci3me7dag364fgp2hccdgzh6zznrvhvfgjzkxrrtmwpa" -AsPlainText -Force Add-TeamAccount -Account http://10.0.0.5:8080/tfs/DefaultCollection -Drive vss -verbose -SecurePersonalAccessToken $secure
Recommended workaround:
I think by separating teamspsdrive from vsteam module will likely workaround the problem.
-
Looking at the code in GetExportedTypesDefinitions, it appears to be a TODO to handle circular dependencies and caching nested module types. We should fix this in 6.1, but existing usage will need to use the workaround particularly if targeting Windows PowerShell 5.1 as well.
DarqueWarrior commented
on Dec 6, 2017 ContributorAuthorMore actionsI just want to confirm that the circular dependencies are implicit and not explicit correct? I don't see where I am referencing the two modules against each other explicitly.
Donovan Brown (@DarqueWarrior) yes, it is implicit due to how SHiPS calls back into the module to access the class since we don't supported exposing classes via ExportedTypes yet.
Was this issue fixed in #6843?
microsoft-github-policy-service commented
on Nov 16, 2023 ContributorMore actionsThis issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented
on Nov 16, 2023 ContributorMore actionsThis issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
- addedResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or more
on Nov 16, 2023 microsoft-github-policy-service commented
on Nov 16, 2023 ContributorMore actionsThis issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented
on Nov 23, 2023 ContributorMore actionsThis issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.
Steps to reproduce
Expected behavior
Actual behavior
Environment data
Workaround
Do not add module path to PSModulePath and the steps below will work.