Skip to content

fix(oidc): do not reuse completed in-flight google metadata token fetch (#53944) - #54312

Open
MilindChatrabhuji wants to merge 1 commit into
BerriAI:mainfrom
MilindChatrabhuji:fix/async-oidc-retry-stale-fetch-53944
Open

MilindChatrabhuji wants to merge 1 commit into
BerriAI:mainfrom
MilindChatrabhuji:fix/async-oidc-retry-stale-fetch-53944

Conversation

@MilindChatrabhuji

Copy link
Copy Markdown

Overview

Fixes #53944

When an async call resolves an oidc/google/<audience> api_key and the metadata server fails, an immediate retry or subsequent call could fail with the same error without querying the metadata server again.

Cause

In _GoogleTokenFetch.start_or_join (litellm/utils.py), self.in_flight was returned whenever it was not None.
In asyncio, callbacks attached via fetch.add_done_callback(self._land) are scheduled on the event loop and are not guaranteed to run before the caller awaiting the fetch resumes. When a caller caught a failure and immediately retried, self.in_flight was still pointing to the completed future, causing start_or_join() to join the finished future and return the stale failure without initiating a new fetch.

Solution

In _GoogleTokenFetch.start_or_join:

if self.in_flight is not None and not self.in_flight.done():
    return self.in_flight

If in_flight is already completed, a new fetch is initiated via run_in_executor and assigned to self.in_flight.

Testing

  1. Added unit tests in tests/unit/test_utils.py:
    • test_google_token_fetch_start_or_join_when_in_flight_is_done_starts_new_fetch: Parameterized with done_status="exception" and done_status="result" to verify that completed futures are not reused and a new fetch is returned.
    • test_google_token_fetch_start_or_join_when_in_flight_is_pending_joins_existing: Verifies that an active in-flight future is properly joined.
  2. Verified test_oidc_google_api_key_fails_closed_when_the_metadata_server_fails_and_recovers_on_the_next_call across 5 consecutive runs with 100% pass rate.

@veria-ai

veria-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: async oidc/google api_key retried right after a metadata failure reuses the failed fetch

1 participant