Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug 903403

It is suspected that host name resolution can fail in /etc/hosts under some circumstances.
We aim to work around this problem by forcing an tolerant encoding when using the Hosts resolver.
  • Loading branch information...
commit e6b05cd465f98efcc83d4c834d91474e39b54d23 1 parent 2102b3a
@BanzaiMan BanzaiMan authored
Showing with 39 additions and 9 deletions.
  1. +7 −6 lib/rhc/commands/app.rb
  2. +32 −3 lib/rhc/helpers.rb
View
13 lib/rhc/commands/app.rb
@@ -417,18 +417,19 @@ def dns_propagated?(host, sleep_time=2)
Kernel.sleep 5
# Now start checking for DNS
- for i in 0..MAX_RETRIES-1
- found = host_exists?(host) || hosts_file_contains?(host)
- break if found
+ host_found = hosts_file_contains?(host) or
+ 1.upto(MAX_RETRIES) { |i|
+ host_found = host_exists?(host)
+ break found if host_found
- say " retry # #{i+1} - Waiting for DNS: #{host}"
+ say " retry # #{i} - Waiting for DNS: #{host}"
Kernel.sleep sleep_time.to_i
sleep_time *= DEFAULT_DELAY_THROTTLE
- end
+ }
debug "End checking for application dns @ '#{host} - found=#{found}'"
- found
+ host_found
end
def enable_jenkins?
View
35 lib/rhc/helpers.rb
@@ -458,9 +458,38 @@ def host_exists?(host)
def hosts_file_contains?(host)
# :nocov:
- resolver = Resolv::Hosts.new
- resolver.getaddress host
- rescue Resolv::ResolvError
+ with_tolerant_encoding do
+ begin
+ resolver = Resolv::Hosts.new
+ resolver.getaddress host
+ rescue Resolv::ResolvError
+ rescue => e
+ debug "Error resolving host with Resolv::Hosts"
+ debug "You can bypass this check with '--no-dns'."
+ debug " #{e.class}"
+ debug " #{e.message}"
+ debug " #{e.backtrace}"
+ end
+ end
+ # :nocov:
+ end
+
+ def with_tolerant_encoding(&block)
+ # :nocov:
+ if RUBY_VERSION.to_f >= 1.9
+ orig_default_internal = Encoding.default_internal
+ Encoding.default_internal = 'ISO-8859-1'
+ else
+ orig_default_kcode = $KCODE
+ $KCODE = 'N'
+ end
+ yield
+ ensure
+ if RUBY_VERSION.to_f >= 1.9
+ Encoding.default_internal = orig_default_internal
+ else
+ $KCODE = orig_default_kcode
+ end
# :nocov:
end
Please sign in to comment.
Something went wrong with that request. Please try again.