Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* lib/resolv.rb (Resolv::DNS): retry IO.select for premature wakeup.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 6533f070ba616662b7ab7504f7bc2a0827394a89 1 parent 687c41d
akr authored October 31, 2011
4  ChangeLog
... ...
@@ -1,3 +1,7 @@
  1
+Mon Oct 31 21:02:43 2011  Tanaka Akira  <akr@fsij.org>
  2
+
  3
+	* lib/resolv.rb (Resolv::DNS): retry IO.select for premature wakeup.
  4
+
1 5
 Mon Oct 31 20:14:22 2011  Tanaka Akira  <akr@fsij.org>
2 6
 
3 7
 	* io.c (fd_set_cloexec): clear CLOEXEC flag for standard file
9  lib/resolv.rb
@@ -657,16 +657,19 @@ def initialize
657 657
       end
658 658
 
659 659
       def request(sender, tout)
660  
-        timelimit = Time.now + tout
  660
+        start = Time.now
  661
+        timelimit = start + tout
661 662
         sender.send
662 663
         while true
663  
-          now = Time.now
664  
-          timeout = timelimit - now
  664
+          before_select = Time.now
  665
+          timeout = timelimit - before_select
665 666
           if timeout <= 0
666 667
             raise ResolvTimeout
667 668
           end
668 669
           select_result = IO.select(@socks, nil, nil, timeout)
669 670
           if !select_result
  671
+            after_select = Time.now
  672
+            next if after_select < timelimit
670 673
             raise ResolvTimeout
671 674
           end
672 675
           begin
6  test/resolv/test_dns.rb
@@ -114,7 +114,8 @@ def test_query_ipv4_address_timeout
114 114
         start = Time.now
115 115
         dns.getresources("foo.example.org", Resolv::DNS::Resource::IN::A)
116 116
       }
117  
-      diff = Time.now - start
  117
+      t2 = Time.now
  118
+      diff = t2 - start
118 119
       assert rv.empty?, "unexpected: #{rv.inspect} (expected empty)"
119 120
       assert_operator 0.1, :<=, diff
120 121
 
@@ -123,7 +124,8 @@ def test_query_ipv4_address_timeout
123 124
         start = Time.now
124 125
         dns.getresources("foo.example.org", Resolv::DNS::Resource::IN::A)
125 126
       }
126  
-      diff = Time.now - start
  127
+      t2 = Time.now
  128
+      diff = t2 - start
127 129
       assert rv.empty?, "unexpected: #{rv.inspect} (expected empty)"
128 130
       assert_operator 0.3, :<=, diff
129 131
     }

0 notes on commit 6533f07

Please sign in to comment.
Something went wrong with that request. Please try again.