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

projectorganizer: Close dir created with g_dir_open() in some special cases #605

Merged
merged 2 commits into from
Oct 2, 2017

Conversation

techee
Copy link
Member

@techee techee commented Sep 27, 2017

At the moment the directory isn't closed when tm_get_real_path() returns
NULL or when the given path was already visited (happens e.g. with
symlink loops).

… cases

At the moment the directory isn't closed when tm_get_real_path() returns
NULL or when the given path was already visited (happens e.g. with
symlink loops).
@techee
Copy link
Member Author

techee commented Sep 27, 2017

@kugel- Would you test this patch? I hope it could fix #604 - otherwise I don't know. Do you use some symlinks that could cause that the same path is re-visited many times? Or something that causes that tm_get_real_path() returns NULL for many files? These are the only two cases in which the directory wasn't properly closed (for normal projects I haven't been able to reproduce the issue - no dirs were open).

Note that if you had 1024 nested directories like

first/second/third/.../1024-th

the current code will still need to open all the intermediate directories for traversal and you'll get the issue during project load. This would be rather hard to fix (or more precisely, the traversal would have to be slow because the intermediate dirs would have to be re-opened closed all the time) but this is a rather crazy case so I'll leave it as it is.

…children

At the moment the code calls g_dir_open() for the current dir, then
recurses to its children and finally closes the dir. This makes the
intermediate dirs open until the recursion returns and could potentially
cause too many open fd if the directory structure is extremely deep.

Instead, get all children of a directory first, close the directory and
then recurse into the remembered subdirectories.
@techee
Copy link
Member Author

techee commented Sep 28, 2017

Disregard my previous comment about the deeply nested directories - it's easy to fix and I've added a patch that does that so now there's at most 1 directory open during traversal.

Anyway, the second patch is just a bonus - it's not something that could cause that many fd's are open after the project is loaded and not the cause of the original problem.

@b4n
Copy link
Member

b4n commented Sep 29, 2017

LGTM. First commit makes a lot of sense and fixes and actual possible issue. Second seems a little more theoretical and slightly slower in the regular case, but fair enough anyway.

@elextr
Copy link
Member

elextr commented Sep 29, 2017

LGTM

@b4n, I would have said the second would be faster, reading everything while its all cached, but anyway it hardly matters in a function doing so much IO.

@techee
Copy link
Member Author

techee commented Sep 30, 2017

And to have all opinions covered, I think the real-world speed will be identical :-).

@kugel-
Copy link
Member

kugel- commented Oct 2, 2017

Your changes seem to work. Thank you. I didn't test the first fix individually, just the HEAD of your branch.

@techee
Copy link
Member Author

techee commented Oct 2, 2017

@kugel- Good, thanks for testing.

@frlan OK to merge?

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.

5 participants