From 41bb5f13b2053e24b7b176a704a14d26daf80125 Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Tue, 8 Oct 2019 11:33:03 -0700 Subject: [PATCH] fix: Increase metadata timeout, matching the logic in google-cloud-env --- lib/googleauth/compute_engine.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/googleauth/compute_engine.rb b/lib/googleauth/compute_engine.rb index 9ca243a..08ecf66 100644 --- a/lib/googleauth/compute_engine.rb +++ b/lib/googleauth/compute_engine.rb @@ -59,20 +59,14 @@ module Google extend Memoist # Detect if this appear to be a GCE instance, by checking if metadata - # is available + # is available. def on_gce? options = {} + # TODO: This should use google-cloud-env instead. c = options[:connection] || Faraday.default_connection headers = { "Metadata-Flavor" => "Google" } resp = c.get COMPUTE_CHECK_URI, nil, headers do |req| - # Comment from: oauth2client/client.py - # - # Note: the explicit `timeout` below is a workaround. The underlying - # issue is that resolving an unknown host on some networks will take - # 20-30 seconds; making this timeout short fixes the issue, but - # could lead to false negatives in the event that we are on GCE, but - # the metadata resolution was particularly slow. The latter case is - # "unlikely". - req.options.timeout = 0.1 + req.options.timeout = 1.0 + req.options.open_timeout = 0.1 end return false unless resp.status == 200 resp.headers["Metadata-Flavor"] == "Google"