Resolv::DNS: TCP fallback fails with multiple resolvers
|ruby -v:||ruby 1.8.7 (2011-12-28 patchlevel 357) [i686-darwin11]||Backport:||1.9.3: UNKNOWN, 2.0.0: UNKNOWN|
Since my TCP fallback support patch from #3835 was merged Resolv::DNS would sometimes fail with a @"host/port don't match: :"@ @Resolv::DNS::Requester::RequestError@ exception in @resolv.rb@, line 818 (Ruby 1.9.1). This happens when more than one nameserver is configured and Resolv::DNS is has fallen back to TCP and rotates from the first to the second nameserver (e.g., when there was a timeout in the TCP query to the first nameserver).
#1 Updated by Julian Mehnle almost 2 years ago
- File ruby-trunk-8285-resolv-tcp-fallback-fix.diff added
The problem is caused by my original TCP fallback code reusing a Resolv::DNS::Requester::TCP::Sender object that was initialized for one (the first) nameserver with a Resolv::DNS::Requester::TCP object that was initialized for another (the second) nameserver, and the TCP requester detecting a host/port mismatch between itself and the sender. (The fact that both the requester and the sender are aware of the nameserver's host and port is a design bug in the original code, but I opted not to fix that.)
This patch fixes my original TCP fallback code to keep one sender per requester, thereby avoiding mismatch situations. (Also this patch gracefully handles the nameserver refusing a TCP connection (raised as an Errno::ECONNREFUSED exception) by treating it like a timeout.)