[ruby-core:86634] Re: [Ruby trunk Bug#14681] `syswrite': stream closed in another thread (IOError)

From: Eric Wong <normalperson@...>
Date: 2018-04-21 03:25:16 UTC
List: ruby-core #86634
[email protected] wrote:
> Bug #14681: `syswrite': stream closed in another thread (IOError)
> https://bugs.ruby-lang.org/issues/14681

There's two bugs, here, I think.  I made r63216 because it
became obvious to me with the timeline shown in the commit message:

   https://80x24.org/spew/[email protected]/raw

However, I have a work-in-progress fix which probably requires
API rework for rb_thread_io_blocking_region:


   https://80x24.org/spew/[email protected]/
   Note: the /* TODO: check func() */ in rb_thread_io_blocking_region
   But that WIP patch is broken...

   I think we need to replace rb_thread_io_blocking_region to
   permanently fix your problem.  My change to check "val != Qundef"
   is insufficient and wrong.  But I don't know how reasonable close
   notifications can be with APIs like IO.copy_stream and
   IO.select which work on multiple IOs, even...

   However, you can work around the problem simply:

> 100.times.collect do
> 	Thread.new do
> 		input, output = IO.pipe
> 		
> 		worker = Thread.new do
> 			sleep(0.1)
> 			output.syswrite('.')
> 		end
> 		
> 		input.read(1)
> 		
> 		input.close
> 		output.close
> 		worker.join

You should be able to rearrange the order of the last two calls
so worker.join happens before output.close:

		worker.join
		output.close

Thats should avoid the problem described in
   https://80x24.org/spew/[email protected]/

> 	end
> end.each(&:join)
> ```

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread