Bug #745: IO associates with the file descriptor, not the stream
http://redmine.ruby-lang.org/issues/show/745

Author: Jim Deville
Status: Open, Priority: Normal

When IO.new is called with a file descriptor, it is linked to the file descriptor, not the associated stream.

f = File.open("test.rb", "w") #f.to_i == 3 on windows
i = IO.new(f.to_i, "w") 
f.close #file descriptor 3 is now free'd, so it can be reused
g = File.open("test2","w") # g.to_i == 3 because f was closed
i.write "foo" #the stream that i was opened on is now closed, but i is still active
i.flush

i.close #this closes the stream! Not just the FD
g.close #this throws an error, because i.close closed g's stream

This has been observed on Windows, and OS X with Ruby 1.8.6 p111. I expect i.write to fail because the stream has already been closed. If there is good reason to keep i associated with the fd, then i.close shouldn't close g.


----------------------------------------
http://redmine.ruby-lang.org