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

Cyclic rescursion with a Symbolic link in a PSModulePath will hang the creation of ModuleAnalysisCache & hang TabCompletion #10667

Open
kilasuit opened this issue Oct 1, 2019 · 7 comments
Labels
Issue-Bug Issue has been identified as a bug in the product Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Engine core PowerShell engine, interpreter, and runtime WG-NeedsReview Needs a review by the labeled Working Group

Comments

@kilasuit
Copy link
Collaborator

kilasuit commented Oct 1, 2019

This issue was diagnosed in the PowerShell Slack off of the back of this message from @TheMusicMeister

image

Whilst this issue was found on Windows in PowerShell v5.1.18362.145, I've tested and confirmed this is still an issue in v5.1.18990.1, v6.2.3 & v7.0.0.preview.4 & we have managed to track down the issue to being an issue with there being a case of cyclic recursion on trying to find all modules in a PSModulePath due to a Symbolic Link being nested within one of the paths in PSModulePath and it pointing to a directory nested within one of the paths listed in the PSModulePath

Steps to reproduce

This is a simplified reproduction but achieves the same issues as reported.

Create a symbolic link at C:\Tools\Modules\Subpath\ that links to C:\Tools\Modules & then add C:\Tools\ as a path in the PSModulePath
Once created remove your Module Analysis Cache (simple rename works) then run Get-Module -ListAvailable -All -Refresh to completely recreate the cache, optionally running Trace-Command -PSHost -Name Modules -Expression { Get-Module -ListAvailable -All -Refresh } to see progress of the recreation of the Module Analysis Cache

Eventually (with enough folders to traverse thorough) this will hang the console which has the

Expected behavior

PowerShell ideally should intelligently realise that it's in a directory that contains a symbolic link that links to a parent directory that is already contained in the PSModulePath and skip it entirely. However to do so would require changes to the current behaviour and this is a relatively niche error that I wouldn't expect to see all that often.

Actual behavior

PowerShell will consume memory whilst trying to recursively search all entries in the PSModulePath and will then eventually throw the below error in (v6.2.3 & v.7.0.0.preview4 unsure on v5.1)
**
image
**

Environment data

v7.0.0.preview.4
v6.2.3
v5.1.18990.1
v5.1.18362.145
Windows 10

@kilasuit kilasuit added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Oct 1, 2019
@iSazonov
Copy link
Collaborator

I guess the issue is for native command discovery too. Also completers can have another code paths to process PSModulePath. User's code also can be affected.
So we would have to check PSModulePath at every read time of the env variable. It is very perf expensive fix.

Default PSModulePath has not broken links and only user himself can add suck links. So it looks like an edge case and I'd do not fix anything as "won't fix".

@iSazonov iSazonov added the WG-Engine core PowerShell engine, interpreter, and runtime label Jan 31, 2020
@iSazonov
Copy link
Collaborator

We could add Depth check in the file enumeration.

@iSazonov iSazonov added Issue-Bug Issue has been identified as a bug in the product Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors and removed Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a labels Jan 15, 2021
Copy link
Contributor

This 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.

2 similar comments
Copy link
Contributor

This 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.

Copy link
Contributor

This 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 microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 16, 2023
Copy link
Contributor

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

@kilasuit kilasuit reopened this Nov 24, 2023
@kilasuit kilasuit added WG-NeedsReview Needs a review by the labeled Working Group and removed Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 24, 2023
@kilasuit
Copy link
Collaborator Author

Reopening as this I think still needs reviewed whether or not this is still an issue, I'd do more investigation into this if personal circumstances weren't a current blocker for me to be able to do so properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Issue has been identified as a bug in the product Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Engine core PowerShell engine, interpreter, and runtime WG-NeedsReview Needs a review by the labeled Working Group
Projects
None yet
Development

No branches or pull requests

2 participants