Skip to content
  • Koichi Sasada's avatar
    5c2b6441
    fix random EBADF problem · 5c2b6441
    Koichi Sasada authored
    ```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.
    5c2b6441
    fix random EBADF problem
    Koichi Sasada authored
    ```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.
Loading