[前][次][番号順一覧][スレッド一覧]

ruby-changes:31035

From: nobu <ko1@a...>
Date: Wed, 2 Oct 2013 14:20:10 +0900 (JST)
Subject: [ruby-changes:31035] nobu:r43114 (trunk): io.c: get rid of race condition

nobu	2013-10-02 14:20:02 +0900 (Wed, 02 Oct 2013)

  New Revision: 43114

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43114

  Log:
    io.c: get rid of race condition
    
    * io.c (rb_io_close_write): detach tied IO for writing before closing
      to get rid of race condition.  [ruby-list:49598]

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/ruby/test_io.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43113)
+++ ChangeLog	(revision 43114)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Wed Oct  2 14:18:56 2013  Nobuyoshi Nakada  <nobu@r...>
+Wed Oct  2 14:19:57 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (rb_io_close_write): detach tied IO for writing before closing
+	  to get rid of race condition.  [ruby-list:49598]
 
 	* io.c (rb_io_close_read): keep fptr in write_io to be discarded, to
 	  fix freed pointer access when it is in use by other threads, and get
Index: io.c
===================================================================
--- io.c	(revision 43113)
+++ io.c	(revision 43114)
@@ -4492,12 +4492,12 @@ rb_io_close_write(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4492
 	rb_raise(rb_eIOError, "closing non-duplex IO for writing");
     }
 
-    rb_io_close(write_io);
     if (io != write_io) {
 	GetOpenFile(io, fptr);
 	fptr->tied_io_for_writing = 0;
 	fptr->mode &= ~FMODE_DUPLEX;
     }
+    rb_io_close(write_io);
     return Qnil;
 }
 
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 43113)
+++ test/ruby/test_io.rb	(revision 43114)
@@ -1380,6 +1380,19 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L1380
     end
   end
 
+  def test_close_read_write_separately
+    bug = '[ruby-list:49598]'
+    (1..10).each do |i|
+      assert_nothing_raised(IOError, "#{bug} trying ##{i}") do
+        IO.popen(EnvUtil.rubybin, "r+") {|f|
+          th = Thread.new {f.close_write}
+          f.close_read
+          th.join
+        }
+      end
+    end
+  end
+
   def test_pid
     r, w = IO.pipe
     assert_equal(nil, r.pid)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]