| The EC2 fact is resolved only if hypervisor is AWS. About the AZ metadata, i think something is funky with the http client on Windows, and it does not respect the set timeouts. The following snippet can be used to reproduce the issue:
require 'net/http' |
require 'uri' |
require 'benchmark' |
|
url = URI.parse("http://169.254.169.254/metadata/instance?api-version=2020-09-01") |
http = Net::HTTP.new(url.host, url.port) |
http.read_timeout = 1 |
http.open_timeout = 1 |
p Benchmark.realtime { |
begin |
resp = http.start() { |http| http.get(url.path) } |
rescue Net::OpenTimeout => e |
puts e.message |
end |
}
|
Another thing, the errors are different, `Net::OpenTimeout` on Windows after 20 seconds, even though `open_timeout` is set to 5, `Errno::ENETUNREACH` on linux and the connection is closed immediately . |