summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--io.c3
-rw-r--r--test/ruby/test_io.rb20
3 files changed, 30 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index fb72bc0d40..7a4154507a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Jun 18 23:59:24 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (fill_cbuf): finish reading at EOF, and the readconv has
+ been cleared by another thread while io_fillbuf() is waiting at
+ select(). a patch in [ruby-core:37197] by Hiroshi Shirosaki
+ <h.shirosaki AT gmail.com>. fixed #3840
+
Sat Jun 18 21:36:29 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* thread_pthread.c: remove GVL_DEBUG
diff --git a/io.c b/io.c
index fae297990a..4371d5388a 100644
--- a/io.c
+++ b/io.c
@@ -1717,6 +1717,9 @@ fill_cbuf(rb_io_t *fptr, int ec_flags)
if (fptr->rbuf.len == 0) {
READ_CHECK(fptr);
if (io_fillbuf(fptr) == -1) {
+ if (!fptr->readconv) {
+ return MORE_CHAR_FINISHED;
+ }
ds = dp = (unsigned char *)fptr->cbuf.ptr + fptr->cbuf.off + fptr->cbuf.len;
de = (unsigned char *)fptr->cbuf.ptr + fptr->cbuf.capa;
res = rb_econv_convert(fptr->readconv, NULL, NULL, &dp, de, 0);
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 3df7771d6c..0325867496 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1955,4 +1955,24 @@ End
assert_nothing_raised(TypeError) { File.binwrite(path, "string", mode: "w", encoding: "EUC-JP") }
end
end
+
+ def test_race_between_read
+ file = Tempfile.new("test")
+ path = file.path
+ file.close
+ write_file = File.open(path, "wt")
+ read_file = File.open(path, "rt")
+
+ threads = []
+ 10.times do |i|
+ threads << Thread.new {write_file.print(i)}
+ threads << Thread.new {read_file.read}
+ end
+ threads.each {|t| t.join}
+ assert(true, "[ruby-core:37197]")
+ ensure
+ read_file.close
+ write_file.close
+ file.close!
+ end
end