* [ruby-core:86655] cross-thread IO#close semantics
@ 2018-04-23 13:39 Eric Wong
2018-05-15 9:53 ` [ruby-core:87040] " Eric Wong
0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2018-04-23 13:39 UTC (permalink / raw)
To: ruby-core
Related to the discussion on [Bug #14681]
I found an old Ruby 1.8 installation, and the following code
exits after 100ms with: [IOError, "stream closed"]
1.9 and later hangs forever:
r, w = IO.pipe
th = Thread.new do
begin
IO.select([r])
rescue => e
warn [ e.class, e.message ].inspect
end
end
sleep 0.1
r.close
th.join
Of course I know why: it's not implemented in 1.9+;
rb_thread_io_blocking_region only cares for operations on the
single FD case, multiplexing functions like select aren't
supported. I could implement it, but it has overhead and maybe
nobody cares for this feature. IO.select is an inefficient API
anyways
This also pertains to [Feature #13618] for auto-fiber/green thread
support or whatever it will be called.
If I replace IO.select with single FD operation which hits
rb_thread_io_blocking_region in 1.9+ such as "r.read", then Ruby
behaves consistently in 1.8/1.9/2.x
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:87040] Re: cross-thread IO#close semantics
2018-04-23 13:39 [ruby-core:86655] cross-thread IO#close semantics Eric Wong
@ 2018-05-15 9:53 ` Eric Wong
0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2018-05-15 9:53 UTC (permalink / raw)
To: ruby-core
Likewise, IO.copy_stream also fails to detect cross-thread
IO#close because it does not use waiting_fd infrastructure
in rb_thread_io_blocking_region.
```
r, w = IO.pipe
th = Thread.new do
begin
IO.copy_stream(r, '/dev/null')
rescue => e
warn [ e.class, e.message ].inspect
end
end
sleep 0.1
r.close
th.join
```
Should I change IO.copy_stream and IO.select to avoid
stuck threads in these cases?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-15 9:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-23 13:39 [ruby-core:86655] cross-thread IO#close semantics Eric Wong
2018-05-15 9:53 ` [ruby-core:87040] " Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).