Skip to content

Commit

Permalink
fix: retry token request on retryable status code
Browse files Browse the repository at this point in the history
  • Loading branch information
tommilligan committed Jul 31, 2024
1 parent 40b9ed9 commit 657dc04
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion google/auth/compute_engine/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from google.auth import environment_vars
from google.auth import exceptions
from google.auth import metrics
from google.auth import transport
from google.auth._exponential_backoff import ExponentialBackoff

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -204,7 +205,17 @@ def get(
for attempt in backoff:
try:
response = request(url=url, method="GET", headers=headers_to_use)
break
if response.status in transport.DEFAULT_RETRYABLE_STATUS_CODES:
_LOGGER.warning(
"Compute Engine Metadata server unavailable on "
"attempt %s of %s. Response status: %s",
attempt,
retry_count,
response.status,
)
continue
else:
break

except exceptions.TransportError as e:
_LOGGER.warning(
Expand Down

0 comments on commit 657dc04

Please sign in to comment.