From: "H.Yamamoto" Date: 2005-01-06T16:08:18+09:00 Subject: [ruby-dev:25414] 1.9.0で使用済みソケットが回収されない? 山本です。 1.9.0のbcc32でtest/drbが止まるのを調べていて気づいたのですが、 どうも、1.9.0では使用済みソケットが回収されていないように見えます。 下のパッチを当てて test/drb を実行すると、1.8.2 ではファイルハンドルの 値(ハンドルテーブルのインデックス)が適宜減るのに対して、1.9.0 では 増えつづけ、最後には 152 に達します。 ruby -rsocket -e "50.times { TCPSocket.open(???, ???) }" のようなコードでも再現できます。 /////////////////////////// // 1.8.2(random.c はとりあえずコンパイルを通すため) Index: random.c =================================================================== RCS file: /src/ruby/random.c,v retrieving revision 1.30.2.6 diff -u -w -b -p -r1.30.2.6 random.c --- random.c 5 Jan 2005 11:31:41 -0000 1.30.2.6 +++ random.c 6 Jan 2005 05:05:51 -0000 @@ -275,7 +275,10 @@ random_seed() memset(digits, 0, big->len * SIZEOF_BDIGITS); #ifdef S_ISCHR - if ((fd = open("/dev/urandom", O_RDONLY|O_NONBLOCK + if ((fd = open("/dev/urandom", O_RDONLY +#ifdef O_NONBLOCK + |O_NONBLOCK +#endif #ifdef O_NOCTTY |O_NOCTTY #endif Index: win32/win32.c =================================================================== RCS file: /src/ruby/win32/win32.c,v retrieving revision 1.103.2.17 diff -u -w -b -p -r1.103.2.17 win32.c --- win32/win32.c 5 Jan 2005 01:50:06 -0000 1.103.2.17 +++ win32/win32.c 6 Jan 2005 06:09:21 -0000 @@ -2228,6 +2228,9 @@ rb_w32_socket(int af, int type, int prot fd = rb_w32_open_osfhandle(s, O_RDWR|O_BINARY); } }); + + printf(">>>> %d\n", fd); + return fd; } E:\ruby_1_8\win32\bin>testrb e:/ruby-cvs/ruby_1_8/test/drb >>>> 4 >>>> 5 Loaded suite drb Started (snip) >>>> 4 >>>> 11 >>>> 6 >>>> 21 .>>>> 3 >>>> 4 >>>> 13 >>>> 6 >>>> 26 .>>>> 3 >>>> 4 >>>> 15 >>>> 6 >>>> 22 ........... Finished in 42.262 seconds. 69 tests, 362 assertions, 0 failures, 0 errors /////////////////////////// // 1.9.0 Index: win32/win32.c =================================================================== RCS file: /src/ruby/win32/win32.c,v retrieving revision 1.139 diff -u -w -b -p -r1.139 win32.c --- win32/win32.c 5 Jan 2005 08:00:50 -0000 1.139 +++ win32/win32.c 6 Jan 2005 06:10:29 -0000 @@ -2252,6 +2252,9 @@ rb_w32_socket(int af, int type, int prot fd = rb_w32_open_osfhandle(s, O_RDWR|O_BINARY); } }); + + printf(">>>> %d\n", fd); + return fd; } E:\ruby-cvs\win32>.\ruby ..\ruby\runruby.rb --ext=".ext" -- -v ..\ruby\bin\testr b e:/ruby-cvs/ruby/test/drb ruby 1.9.0 (2005-01-06) [i386-mswin32] >>>> 3 Loaded suite drb Started (snip) >>>> 146 .>>>> 3 >>>> 4 >>>> 148 >>>> 149 .>>>> 3 >>>> 4 >>>> 151 >>>> 152 ........... Finished in 22.594 seconds. 62 tests, 353 assertions, 0 failures, 0 errors