From 61701ae1675f790ee3f59207283642dbe64c2d37 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 25 Jan 2017 14:34:07 +0000 Subject: io.c: close before wait * io.c (io_close_fptr): notify then close, and wait for other threads before free fptr. [ruby-core:79262] [Bug #13158] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 4c224a247f..b16662cd42 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -3397,6 +3397,27 @@ __END__ end; end + def test_race_closed_stream + bug13158 = '[ruby-core:79262] [Bug #13158]' + closed = nil + IO.pipe do |r, w| + thread = Thread.new do + begin + while r.gets + end + ensure + closed = r.closed? + end + end + sleep 0.01 + r.close + assert_raise_with_message(IOError, /stream closed/) do + thread.join + end + assert_equal(true, closed, "#{bug13158}: stream should be closed") + end + end + if RUBY_ENGINE == "ruby" # implementation details def test_foreach_rs_conversion make_tempfile {|t| -- cgit v1.2.3