[前][次][番号順一覧][スレッド一覧]

ruby-changes:69454

From: Koichi <ko1@a...>
Date: Tue, 26 Oct 2021 11:50:39 +0900 (JST)
Subject: [ruby-changes:69454] 5c2b644166 (master): fix random EBADF problem

https://git.ruby-lang.org/ruby.git/commit/?id=5c2b644166

From 5c2b6441660cdabf1efc745c25f2b1a41bb3b087 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Tue, 26 Oct 2021 11:35:57 +0900
Subject: fix random EBADF problem

```ruby
      r, w = IO.pipe
      r.close

      IO.for_fd(w.fileno).close
```

This code closes a file descriptor `w.fileno`, but `w` doesn't know
the closing. Another code can open same file descriptor with opening
file (`f`). After that, the `w` will GCed and `w.fileno` is closed
again, and `f.fileno` is closed too, so IO operations for `f` (`f.close`)
will cause EBADF.

To fix this issue, do this test in another process.
---
 test/-ext-/wait/test_wait.rb | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/test/-ext-/wait/test_wait.rb b/test/-ext-/wait/test_wait.rb
index 79127c041b5..8e53f067cf3 100644
--- a/test/-ext-/wait/test_wait.rb
+++ b/test/-ext-/wait/test_wait.rb
@@ -12,14 +12,18 @@ class TestWait < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/wait/test_wait.rb#L12
   end
 
   def test_wait_for_invalid_fd
-    r, w = IO.pipe
-    r.close
+    assert_separately [], <<~'RUBY'
+      require '-test-/wait'
 
-    IO.for_fd(w.fileno).close
+      r, w = IO.pipe
+      r.close
 
-    assert_raise(Errno::EBADF) do
-      IO.io_wait(w, IO::WRITABLE, nil)
-    end
+      IO.for_fd(w.fileno).close
+
+      assert_raise(Errno::EBADF) do
+        IO.io_wait(w, IO::WRITABLE, nil)
+      end
+    RUBY
   end
 
   def test_wait_for_closed_pipe
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]