ruby-changes:20335
From: yugui <ko1@a...>
Date: Sun, 3 Jul 2011 21:24:37 +0900 (JST)
Subject: [ruby-changes:20335] yugui:r32383 (ruby_1_9_2): merges r32062 from trunk into ruby_1_9_2.
yugui 2011-07-03 21:24:07 +0900 (Sun, 03 Jul 2011) New Revision: 32383 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32383 Log: merges r32062 from trunk into ruby_1_9_2. -- * ext/socket/unixsocket.c (unix_send_io): race condition fixed. (unix_recv_io): ditto. fixed by Eric Wong. [ruby-core:35574] * test/socket/test_unix.rb: test added for above problem. Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/ext/socket/unixsocket.c branches/ruby_1_9_2/test/socket/test_unix.rb branches/ruby_1_9_2/version.h Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 32382) +++ ruby_1_9_2/ChangeLog (revision 32383) @@ -1,3 +1,11 @@ +Mon Jun 13 23:05:01 2011 Tanaka Akira <akr@f...> + + * ext/socket/unixsocket.c (unix_send_io): race condition fixed. + (unix_recv_io): ditto. + fixed by Eric Wong. [ruby-core:35574] + + * test/socket/test_unix.rb: test added for above problem. + Thu May 12 12:24:22 2011 Nobuhiro Iwamatsu <iwamatsu@n...> * ext/openssl/ossl_ssl.c: By trunk@31346, function check of SSLv2 is executed. Index: ruby_1_9_2/ext/socket/unixsocket.c =================================================================== --- ruby_1_9_2/ext/socket/unixsocket.c (revision 32382) +++ ruby_1_9_2/ext/socket/unixsocket.c (revision 32383) @@ -248,9 +248,10 @@ #endif arg.fd = fptr->fd; - rb_thread_fd_writable(arg.fd); - if ((int)BLOCKING_REGION(sendmsg_blocking, &arg) == -1) - rb_sys_fail("sendmsg(2)"); + while ((int)BLOCKING_REGION_FD(sendmsg_blocking, &arg) == -1) { + if (!rb_io_wait_writable(arg.fd)) + rb_sys_fail("sendmsg(2)"); + } return Qnil; } @@ -334,9 +335,10 @@ #endif arg.fd = fptr->fd; - rb_thread_wait_fd(arg.fd); - if ((int)BLOCKING_REGION(recvmsg_blocking, &arg) == -1) - rb_sys_fail("recvmsg(2)"); + while ((int)BLOCKING_REGION_FD(recvmsg_blocking, &arg) == -1) { + if (!rb_io_wait_readable(arg.fd)) + rb_sys_fail("recvmsg(2)"); + } #if FD_PASSING_BY_MSG_CONTROL if (arg.msg.msg_controllen < sizeof(struct cmsghdr)) { Index: ruby_1_9_2/version.h =================================================================== --- ruby_1_9_2/version.h (revision 32382) +++ ruby_1_9_2/version.h (revision 32383) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 282 +#define RUBY_PATCHLEVEL 283 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_2/test/socket/test_unix.rb =================================================================== --- ruby_1_9_2/test/socket/test_unix.rb (revision 32382) +++ ruby_1_9_2/test/socket/test_unix.rb (revision 32383) @@ -6,6 +6,8 @@ require "test/unit" require "tempfile" require "tmpdir" +require "thread" +require "io/nonblock" class TestSocket_UNIXSocket < Test::Unit::TestCase def test_fd_passing @@ -102,6 +104,41 @@ io_ary.each {|io| io.close if !io.closed? } end + def test_fd_passing_race_condition + r1, w = IO.pipe + s1, s2 = UNIXSocket.pair + s1.nonblock = s2.nonblock = true + aoe = Thread.abort_on_exception + Thread.abort_on_exception = true + lock = Mutex.new + nr = 0 + x = 2 + y = 1000 + begin + s1.send_io(nil) + rescue NotImplementedError + assert_raise(NotImplementedError) { s2.recv_io } + rescue TypeError + thrs = x.times.map do + Thread.new do + y.times do + s2.recv_io.close + lock.synchronize { nr += 1 } + end + end + end + (x * y).times { s1.send_io r1 } + thrs.each { |t| t.join } + assert_equal x * y, nr + ensure + Thread.abort_on_exception = aoe + s1.close + s2.close + w.close + r1.close + end + end + def test_sendmsg return if !defined?(Socket::SCM_RIGHTS) IO.pipe {|r1, w| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/