Unverified Commit c020e502 authored by Qianli Scott Zhu's avatar Qianli Scott Zhu Committed by GitHub
Browse files

Add shorter timeout for GCP util. (#4762)

* Add shorter timeout for GCP util.

* Add comment for change reason and unit for timeout.
parent 70b176a9
......@@ -25,7 +25,10 @@ GCP_METADATA_HEADER = {"Metadata-Flavor": "Google"}
def on_gcp():
"""Detect whether the current running environment is on GCP."""
try:
response = requests.get(GCP_METADATA_URL, headers=GCP_METADATA_HEADER)
# Timeout in 5 seconds, in case the test environment has connectivity issue.
# There is not default timeout, which means it might block forever.
response = requests.get(
GCP_METADATA_URL, headers=GCP_METADATA_HEADER, timeout=5)
return response.status_code == 200
except requests.exceptions.RequestException:
return False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment