-
Notifications
You must be signed in to change notification settings - Fork 13
Update util.rb to fix closing of file. #39
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
When attempting to close files, the /proc/self loop was trying to close a file being converted to an integer which was causing issues on Fedora 42, this resolved the problem.
For people searching this is the error that was flagging:
|
If I understand this code correctly, it's trying to close each numbered file descriptor. The |
The function to close the file handle should be on the handle and not the handle converted to an integer, the to_i is being filtered in the if statement above? So for example the code should be: However I'm not a ruby dev so maybe my understanding of the code is incorrect |
I think what it is doing is closing all file descriptors other than stdin, stdout, stderr, and whatever fd 3 is. 🙂 It does not use the full path in |
I think that's what is intended but the to_i is possibly getting in the way... I have Fedora 40 which does work (or silently fails) where as Fedora 42 gives the aforementioned error. |
@adamboutcher Could you try adding The line should probably look like this: if %{^\d+$}.match?(f) && f.to_i >= 3 |
To be clear, I think the change should look like this: diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 06c7b11815..66be0f7da3 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -479,7 +479,7 @@ module Util
begin
Dir.foreach('/proc/self/fd') do |f|
- if f != '.' && f != '..' && f.to_i >= 3
+ if %{^\d+$}.match?(f) && f.to_i >= 3
begin
IO.new(f.to_i).close
rescue But I'm not seeing this problem for whatever reason, so I can't easily test it. |
Will test it when I'm back in the office on Friday.
…On Tue, 22 Apr 2025, 6:02 pm Steven Pritchard, ***@***.***> wrote:
To be clear, I think the change should look like this:
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 06c7b11815..66be0f7da3 100644--- a/lib/puppet/util.rb+++ b/lib/puppet/util.rb@@ -479,7 +479,7 @@ module Util
begin
Dir.foreach('/proc/self/fd') do |f|- if f != '.' && f != '..' && f.to_i >= 3+ if %{^\d+$}.match?(f) && f.to_i >= 3
begin
IO.new(f.to_i).close
rescue
But I'm not seeing this problem for whatever reason, so I can't easily
test it.
—
Reply to this email directly, view it on GitHub
<#39 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOSVCZUN26B6EAENIWXLAD22ZY3NAVCNFSM6AAAAAB3T4OKVWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMRRHE2DQNRYGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
*silug* left a comment (OpenVoxProject/puppet#39)
<#39 (comment)>
To be clear, I think the change should look like this:
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 06c7b11815..66be0f7da3 100644--- a/lib/puppet/util.rb+++ b/lib/puppet/util.rb@@ -479,7 +479,7 @@ module Util
begin
Dir.foreach('/proc/self/fd') do |f|- if f != '.' && f != '..' && f.to_i >= 3+ if %{^\d+$}.match?(f) && f.to_i >= 3
begin
IO.new(f.to_i).close
rescue
But I'm not seeing this problem for whatever reason, so I can't easily
test it.
—
Reply to this email directly, view it on GitHub
<#39 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOSVCZUN26B6EAENIWXLAD22ZY3NAVCNFSM6AAAAAB3T4OKVWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMRRHE2DQNRYGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I've tried this on Fedora42 and it seems to work, or at least I dont get any errors... |
A per comment (OpenVoxProject#39 (comment)) in PR(OpenVoxProject#39)
A per comment (OpenVoxProject/puppet#39 (comment)) in Mirrored PR to OpenVox (OpenVoxProject/puppet#39)
@ekohl Do you see any benefit to adding some of your logic from your other PR here? I think they both accomplish the goal. This one guards against any non-integer FD, but yours specifically filters out the ones we expect. I'm not sure if there are other edge cases we need to consider. |
I don't think this actually resolves it. The file descriptor is the last number. If this avoids the error I think it won't close anything at all anymore. I'd suggest reverting this and applying my patch. See the linked bugzilla for minimal reproducer code |
Based on https://bugzilla.redhat.com/show_bug.cgi?id=2349352#c9 a reproducer to show this broke the code: #!/usr/bin/env ruby
d = Dir.new('/proc/self/fd')
d.each_child do |f|
if %{^\d+$}.match?(f) && f.to_i >= 3
begin
puts "Closing #{f}"
IO.new(f.to_i).close
rescue
nil
end
else
puts "Not closing #{f}"
end
end Running it shows it doesn't close anything anymore: $ ruby close1.rb
Not closing 0
Not closing 1
Not closing 2
Not closing 3
Not closing 4
Not closing 5 |
@@ -479,7 +479,7 @@ def safe_posix_fork(stdin = $stdin, stdout = $stdout, stderr = $stderr, &block) | |||
|
|||
begin | |||
Dir.foreach('/proc/self/fd') do |f| | |||
if f != '.' && f != '..' && f.to_i >= 3 | |||
if %{^\d+$}.match?(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.
If you want this to work, it needs to be
if %{^\d+$}.match?(f) && f.to_i >= 3 | |
if %r{^\d+$}.match?(f) && f.to_i >= 3 |
Edit: but then you run into the original issue again, which is that the last file descriptor can't be closed.
I've opened #42 to properly fix the issue. |
When attempting to close files, the /proc/self loop was trying to close a file being converted to an integer which was causing issues on Fedora 42, this resolved the problem.
Also see puppetlabs/puppet#9552