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

Fix file recursion overflow problems #795

Merged
merged 10 commits into from
Nov 28, 2018

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Nov 20, 2018

Aims to fix PowerShell/vscode-powershell#1613.

Rather than using method recursion to process recursive directories, we now use a while loop and a stack and stop recursing at a depth of 64.

It's a naive solution to the problem, but I didn't want to do any sophisticated expensive checks like building a hashmap of paths or testing for symlinks in case that would cause a performance hit (although it might not be very important).

I also added a new logging method to log exceptions in the log that aren't really fatal.

@TylerLeonhardt
Copy link
Member

In the original issue, you said "We might have to build a HashSet every time and ignore files that are already in it."

I think we should have a HashSet so that we don't end up creating ScriptFiles for the same file over and over again.

@rjmholt
Copy link
Contributor Author

rjmholt commented Nov 21, 2018

My only real concern with the HashSet is that in a file with a lot of directories, it could get pretty big. So we'd allocate and allocate and allocate and then collect every time we search a path. I'll do some research though.

@SeeminglyScience
Copy link
Collaborator

I think we should have a HashSet so that we don't end up creating ScriptFiles for the same file over and over again.

For a HashSet to be useful, wouldn't we have to get the real path for every file? iirc the process for doing that is pretty expensive (at this scale at least) and platform specific.

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just one suggestion (that may or may not be misguided 🙂)

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rjmholt + @SeeminglyScience you both made good points on the HashMap approach. It could be too expensive.

this LGTM

@rjmholt
Copy link
Contributor Author

rjmholt commented Nov 21, 2018

Oh oh oh, so I now see the problem with the HashSet method -- the same directory deeper down will be given back as a deeper path from Directory.GetDirectories(); say that odir is a directory and ldir is a link to that directory, then we'll see the following paths:

  • 0 loops: /path/odir/
  • 1 loop: /path/odir/sub/ldir/
  • 2 loops: /path/odir/sub/ldir/sub/ldir/

We couldn't just compare the paths. We'd have to do symlink inspection and that would be costly.

@rjmholt
Copy link
Contributor Author

rjmholt commented Nov 21, 2018

We also need to do something about the BuildInfo file like @rkeithhill suggested

@rjmholt
Copy link
Contributor Author

rjmholt commented Nov 21, 2018

This seems to be the best suggestion I've seen.

Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the logging changes!

@rjmholt rjmholt deleted the limit-file-recursion-depth branch December 12, 2018 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Process terminated bue to StackOverFlow - process terminated with code 3221225725
4 participants