summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c3
-rw-r--r--test/ruby/test_io.rb30
-rw-r--r--thread.c8
-rw-r--r--version.h2
4 files changed, 41 insertions, 2 deletions
diff --git a/io.c b/io.c
index 0cd5414a0d..79ab348871 100644
--- a/io.c
+++ b/io.c
@@ -432,7 +432,7 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd)
if (!READ_DATA_PENDING(fptr)) {\
WAIT_FD_IN_WIN32(fptr);\
rb_io_check_closed(fptr);\
- }\
+ }\
} while(0)
#ifndef S_ISSOCK
@@ -1765,6 +1765,7 @@ io_fillbuf(rb_io_t *fptr)
rb_sys_fail_path(path);
}
}
+ if (r > 0) rb_io_check_closed(fptr);
fptr->rbuf.off = 0;
fptr->rbuf.len = (int)r; /* r should be <= rbuf_capa */
if (r == 0)
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
diff --git a/thread.c b/thread.c
index ad1e500bc3..85dda61b3a 100644
--- a/thread.c
+++ b/thread.c
@@ -2128,14 +2128,22 @@ rb_thread_fd_close(int fd)
{
rb_vm_t *vm = GET_THREAD()->vm;
rb_thread_t *th = 0;
+ int busy;
+ retry:
+ busy = 0;
list_for_each(&vm->living_threads, th, vmlt_node) {
if (th->waiting_fd == fd) {
VALUE err = th->vm->special_exceptions[ruby_error_closed_stream];
rb_threadptr_pending_interrupt_enque(th, err);
rb_threadptr_interrupt(th);
+ busy = 1;
}
}
+ if (busy) {
+ rb_thread_schedule_limits(0);
+ goto retry;
+ }
}
/*
diff --git a/version.h b/version.h
index f903012252..08bc375c2b 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.7"
#define RUBY_RELEASE_DATE "2017-03-26"
-#define RUBY_PATCHLEVEL 425
+#define RUBY_PATCHLEVEL 426
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 3