Repository navigation
fix(oidc): do not reuse completed in-flight google metadata token fetch (#53944) - #54312
Open
MilindChatrabhuji wants to merge 1 commit into
Open
MilindChatrabhuji wants to merge 1 commit into
MilindChatrabhuji wants to merge 1 commit into
Conversation
Contributor
PR overviewNo security issues were found in this pull request. Reviews
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_flightwas returned whenever it was notNone.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_flightwas still pointing to the completed future, causingstart_or_join()to join the finished future and return the stale failure without initiating a new fetch.Solution
In
_GoogleTokenFetch.start_or_join:If
in_flightis already completed, a new fetch is initiated viarun_in_executorand assigned toself.in_flight.Testing
tests/unit/test_utils.py:test_google_token_fetch_start_or_join_when_in_flight_is_done_starts_new_fetch: Parameterized withdone_status="exception"anddone_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.test_oidc_google_api_key_fails_closed_when_the_metadata_server_fails_and_recovers_on_the_next_callacross 5 consecutive runs with 100% pass rate.