In article <hvo66668ztc.fsf / coulee.a02.aist.go.jp>,
  Tanaka Akira <akr / m17n.org> writes:

> resolv.rb 内部でも timeout を使っているので、外で設定した timeout が中
> で捕捉されているようですね。
> 
> まぁ、resolv.rb では(一般にはライブラリでは) TimeoutError は使うべきで
> はないのかも知れませんね。

次のように修正するとどうでしょう?

Index: lib/resolv.rb
===================================================================
RCS file: /src/ruby/lib/resolv.rb,v
retrieving revision 1.6
diff -u -r1.6 resolv.rb
--- lib/resolv.rb	2001/12/18 18:13:25	1.6
+++ lib/resolv.rb	2002/01/13 08:02:06
@@ -258,6 +258,9 @@
   class ResolvError < StandardError
   end
 
+  class ResolvTimeout < TimeoutError
+  end
+
   class Hosts
     DefaultFileName = '/etc/hosts'
 
@@ -426,7 +429,7 @@
           end
           sender.send
           reply = reply_name = nil
-          timeout(tout) { reply, reply_name = q.pop }
+          timeout(tout, ResolvTimeout) { reply, reply_name = q.pop }
           case reply.rcode
           when RCode::NoError
             extract_resources(reply, reply_name, typeclass, &proc)
@@ -753,7 +756,7 @@
                 @nameserver.each {|nameserver|
                   begin
                     yield candidate, tout, nameserver
-                  rescue TimeoutError
+                  rescue ResolvTimeout
                   end
                 }
               }
Index: lib/timeout.rb
===================================================================
RCS file: /src/ruby/lib/timeout.rb,v
retrieving revision 1.9
diff -u -r1.9 timeout.rb
--- lib/timeout.rb	2001/08/20 04:29:58	1.9
+++ lib/timeout.rb	2002/01/13 08:02:06
@@ -28,13 +28,13 @@
 class TimeoutError<Interrupt
 end
 
-def timeout(sec)
+def timeout(sec, exception=TimeoutError)
   return yield if sec == nil
   begin
     x = Thread.current
     y = Thread.start {
       sleep sec
-      x.raise TimeoutError, "execution expired" if x.alive?
+      x.raise exception, "execution expired" if x.alive?
     }
     yield sec
 #    return true
-- 
[田中 哲][たなか あきら][Tanaka Akira]
「ふえろ! わかめちゃん作戦です$(C⊇」(Little Worker, 桂遊生丸)