summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-31 12:03:49 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-31 12:03:49 +0000
commit6533f070ba616662b7ab7504f7bc2a0827394a89 (patch)
tree94cbd9a010a761619b4c8401a80a23d4f06d0618
parent687c41dc4d03ba77cd5c286ab721ce56100120e7 (diff)
* 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
-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 6ff264fa59d..1895ca1d8ce 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 6b4e06ad9dc..b38c42ab3f3 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 9ae0df404f9..3827361e47f 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
}