-
Notifications
You must be signed in to change notification settings - Fork 12
Avoid closing directory we're iterating #42
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
base: main
Are you sure you want to change the base?
Conversation
This is broken and results in not closing any file descriptors.
ignore_fds = ['.', '..', d.fileno.to_s] | ||
d.each_child do |f| | ||
next if ignore_fds.include?(f) || f.to_i < 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at #41 I wonder if we should explicitly exclude the FDs that we want to keep open:
ignore_fds = ['.', '..', d.fileno.to_s] | |
d.each_child do |f| | |
next if ignore_fds.include?(f) || f.to_i < 3 | |
ignore_fds = ['.', '..', stdin.fileno.to_s, stdout.fileno.to_s, stderr.fileno.to_s, d.fileno.to_s] | |
d.each_child do |f| | |
next if ignore_fds.include?(f) |
This version is probably safer. Not sure if it's valid to have no stdin, stdout or stderr.
ignore_fds = ['.', '..', d.fileno.to_s] | |
d.each_child do |f| | |
next if ignore_fds.include?(f) || f.to_i < 3 | |
ignore_fds = ['.', '..'] + [stdin, stdout, stderr, d].filter_map { |f| f&.fileno&.to_s } | |
d.each_child do |f| | |
next if ignore_fds.include?(f) |
What makes me hesitant is that I don't know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little worried we're playing whack-a-mole with things we want to filter out and I'm not sure how to be sure we're being exhaustive about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this is much better than looking at .to_i < 3
and assuming that those file descriptors are stdin, stdout and stderr since it is explicit about what's going on.
And I just noticed this repo doesn't run any of the tests, but when I locally run it I did break them: Lines 597 to 665 in 13dd914
|
Ruby 3.4 started error checking directory access and starts to raise Errno::EBADF. This particular loop iterates on all open file descriptors and one is the directory listing from Dir.foreach. In the past this could have led to leaked file descriptors, but it's unlikely since it's likely the last opened file descriptor and have the highest number. Link: ruby/ruby@f2919bd Link: https://bugzilla.redhat.com/show_bug.cgi?id=2349352
5748bab
to
3f344ab
Compare
This starts with reverting #39 because it's broken and caused a regression. Then I've taken my commits from puppetlabs/puppet#9546.
Ruby 3.4 started error checking directory access and starts to raise Errno::EBADF.
This particular loop iterates on all open file descriptors and one is the directory listing from Dir.foreach.
In the past this could have led to leaked file descriptors, but it's unlikely since it's likely the last opened file descriptor and have the highest number.
Link: ruby/ruby@f2919bd
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2349352