Closing an IO being select'ed in another thread does not resume the thread
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Is this intentional?
r1, w1 = IO.pipe r2, w2 = IO.pipe Thread.new do select([r1, r2]) p :ok end sleep 1 p r1.close # expected: closing r1 resumes select([r1, r2]) in the thread # actual: select([r1, r2]) continues to wait sleep 1 w2 << "foo" # Making r2 readable resumes select([r1, r2]) # And it raises an exception: closed stream (IOError) sleep 1
Incidentally, IO#read is resumed by closing the IO.
r1, w1 = IO.pipe Thread.new do r1.read p :ok end sleep 1 p r1.close # Closing r1 resumes r1.read in the thread # And it raises: stream closed in another thread (IOError) sleep 1