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.
This commit is contained in:
parent
7d4c59203f
commit
5c2b644166
@ -12,14 +12,18 @@ class TestWait < Test::Unit::TestCase
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user