Open ioquatix opened 2 months ago
Calling read/write on a closed socket is a user error, but hanging indefinitely doesn't seem ideal. I think we can manage a flag in SSLSocket
so we can raise IOError
.
What should happen if a thread closes SSLSocket
without sync_close
while another thread is waiting for rb_io_maybe_wait_readable()
on the underlying socket?
I'm on the fence about how this should work.
On the one hand, I understand someone might call io.close
. What happens to other users blocking io.read
?
There are two options:
io.close
is able to cause other operations to abort io.read
etc. However, there are many such operations, and so this implementation is extremely complex. It's current behaviour (does it have race conditions? not sure).io.close
with pending operations fails as a runtime error. In other words, io.close
can fail if you don't cause all other usage to exit first. The implementation of this is more trivial as it's just a reference count.io.close
should simply wait for all operations to finish. In other words, it blocks indefinitely if the io is in use elsewhere.As we see in my example here, and your response about how should sync_close
be handled - it becomes extremely tricky.
@ko1 do you have any thoughts about it? I know you believe that File.open{...}
should be able to close the file in all situations, but I'm not so sure if it's good. If the user writes this
File.open(..) do |io|
Thread.new{io.read}
end
I also believe this is a problem with the program.
SSLSocket
error conditions are not consistent withIO
.io.close
followed byio.read
can result inEBADF
rather thanIOError
.sync_close
,io.close
followed byio.read
will hang. Even if the underlying IO is not closed, I don't think theSSLSocket
instance should continue to work after being closed?Reproduction:
Is this something we can improve?