summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--lib/resolv.rb9
-rw-r--r--test/resolv/test_dns.rb6
3 files changed, 14 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 6ff264fa59..1895ca1d8c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon Oct 31 21:02:43 2011 Tanaka Akira <akr@fsij.org>
+
+ * lib/resolv.rb (Resolv::DNS): retry IO.select for premature wakeup.
+
Mon Oct 31 20:14:22 2011 Tanaka Akira <akr@fsij.org>
* io.c (fd_set_cloexec): clear CLOEXEC flag for standard file
diff --git a/lib/resolv.rb b/lib/resolv.rb
index 6b4e06ad9d..b38c42ab3f 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -657,16 +657,19 @@ class Resolv
end
def request(sender, tout)
- timelimit = Time.now + tout
+ start = Time.now
+ timelimit = start + tout
sender.send
while true
- now = Time.now
- timeout = timelimit - now
+ before_select = Time.now
+ timeout = timelimit - before_select
if timeout <= 0
raise ResolvTimeout
end
select_result = IO.select(@socks, nil, nil, timeout)
if !select_result
+ after_select = Time.now
+ next if after_select < timelimit
raise ResolvTimeout
end
begin
diff --git a/test/resolv/test_dns.rb b/test/resolv/test_dns.rb
index 9ae0df404f..3827361e47 100644
--- a/test/resolv/test_dns.rb
+++ b/test/resolv/test_dns.rb
@@ -114,7 +114,8 @@ class TestResolvDNS < Test::Unit::TestCase
start = Time.now
dns.getresources("foo.example.org", Resolv::DNS::Resource::IN::A)
}
- diff = Time.now - start
+ t2 = Time.now
+ diff = t2 - start
assert rv.empty?, "unexpected: #{rv.inspect} (expected empty)"
assert_operator 0.1, :<=, diff
@@ -123,7 +124,8 @@ class TestResolvDNS < Test::Unit::TestCase
start = Time.now
dns.getresources("foo.example.org", Resolv::DNS::Resource::IN::A)
}
- diff = Time.now - start
+ t2 = Time.now
+ diff = t2 - start
assert rv.empty?, "unexpected: #{rv.inspect} (expected empty)"
assert_operator 0.3, :<=, diff
}