From 8a14ed3df5361398638a16597602b54f8421b905 Mon Sep 17 00:00:00 2001 From: usa Date: Sat, 25 Mar 2017 15:47:52 +0000 Subject: merge revision(s) 57199,57202,57206,57224: [Backport #13076] io.c: fix race between read and close * io.c (io_fillbuf): fix race between read and close, in the case the IO gets closed before the reading thread achieve the lock. [ruby-core:78845] [Bug #13076] thread.c: fix race between read and close * thread.c (rb_thread_fd_close): wait until all threads using the fd finish the operation, not to free the buffer in use. [ruby-core:78845] [Bug #13076] revert a part of r57199 * io.c (io_fillbuf): revert a part of r57199 because it broke IO#getch. see also [Bug #13076] io.c: fix race between read and close * io.c (io_fillbuf): fix race between read and close and bail out in the case the IO gets closed before the reading thread achieve the lock. [ruby-core:78845] [Bug #13076] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 1bf160f2f7..4d712ed099 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -3177,4 +3177,34 @@ End end end end + + def test_race_gets_and_close + assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}") + bug13076 = '[ruby-core:78845] [Bug #13076]' + begin; + 100.times do |i| + a = [] + t = [] + 10.times do + r,w = IO.pipe + a << [r,w] + t << Thread.new do + begin + while r.gets + end + rescue IOError + end + end + end + a.each do |r,w| + w.puts "hoge" + w.close + r.close + end + assert_nothing_raised(IOError, bug13076) { + t.each(&:join) + } + end + end; + end end -- cgit v1.2.3