Skip to content

Commit 657dc04

Browse files
committed
fix: retry token request on retryable status code
1 parent 40b9ed9 commit 657dc04

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

google/auth/compute_engine/_metadata.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from google.auth import environment_vars
2929
from google.auth import exceptions
3030
from google.auth import metrics
31+
from google.auth import transport
3132
from google.auth._exponential_backoff import ExponentialBackoff
3233

3334
_LOGGER = logging.getLogger(__name__)
@@ -204,7 +205,17 @@ def get(
204205
for attempt in backoff:
205206
try:
206207
response = request(url=url, method="GET", headers=headers_to_use)
207-
break
208+
if response.status in transport.DEFAULT_RETRYABLE_STATUS_CODES:
209+
_LOGGER.warning(
210+
"Compute Engine Metadata server unavailable on "
211+
"attempt %s of %s. Response status: %s",
212+
attempt,
213+
retry_count,
214+
response.status,
215+
)
216+
continue
217+
else:
218+
break
208219

209220
except exceptions.TransportError as e:
210221
_LOGGER.warning(

0 commit comments

Comments
 (0)