mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b4aa884f06
commit
08ca33e98c
2 changed files with 32 additions and 1 deletions
1
io.c
1
io.c
|
@ -1775,6 +1775,7 @@ io_fillbuf(rb_io_t *fptr)
|
||||||
rb_syserr_fail_path(e, path);
|
rb_syserr_fail_path(e, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (r > 0) READ_CHECK(fptr);
|
||||||
fptr->rbuf.off = 0;
|
fptr->rbuf.off = 0;
|
||||||
fptr->rbuf.len = (int)r; /* r should be <= rbuf_capa */
|
fptr->rbuf.len = (int)r; /* r should be <= rbuf_capa */
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
|
|
|
@ -3366,6 +3366,36 @@ __END__
|
||||||
end
|
end
|
||||||
end if File::BINARY != 0
|
end if File::BINARY != 0
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
if RUBY_ENGINE == "ruby" # implementation details
|
if RUBY_ENGINE == "ruby" # implementation details
|
||||||
def test_foreach_rs_conversion
|
def test_foreach_rs_conversion
|
||||||
make_tempfile {|t|
|
make_tempfile {|t|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue