Bug #745
closedIO associates with the file descriptor, not the stream
Description
=begin
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.
=end
Updated by rogerdpack (Roger Pack) over 15 years ago
=begin
is this a bug or more of a design decision? [i.e. "should descriptors to the same IO all close together?" is the question].
Thanks!
-=R
=end
Updated by matz (Yukihiro Matsumoto) over 15 years ago
- Status changed from Open to Rejected
=begin
I think the current behavior follows the underlying OS behavior.
When you create an IO object over a file descriptor, every operation of the IO should work on the descriptor. If you want streams work serapratedly, you should dup the descriptor explicitly.
Am I missing something?
=end