-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
This is broken and results in not closing any file descriptors.
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
@ekohl Have you been able to test this change and make sure it doesn't break anything? Looks okay to me, but I'm not super knowledgeable about this area. |
It's already rolled out in Fedora 42 and I wrote a test there. Without the patch anything that execs (like the exec resource) just straight up fails. With the patch it works again. See the linked bugzilla for more details. The micro-reproducers there give confidence it's correct |
https://docs.fedoraproject.org/en-US/defensive-coding/tasks/Tasks-Descriptors/#sect-Defensive_Coding-Tasks-Descriptors-Child_Processes talks about methodologies for this exact thing. It looks like ruby for some reason doesn't use FD_CLOEXEC/O_CLOEXEC to ensure they close on fork end. |
The Fedora page mentions that has a race condition. This implements the approach 2 it mentions: loop over My suggestion of using open3 would use a better system call to avoid all thr code, but is a much bigger refactor |
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