FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

dataconnect(fix): fix potential infinite loop when Auth and/or App Check tokens refreshed by dconeybe · Pull Request #8319 · firebase/firebase-android-sdk · GitHub

dataconnect(fix): fix potential infinite loop when Auth and/or App Check tokens refreshed - #8319

Merged
dconeybe merged 2 commits into
mainfrom
dconeybe/dataconnect/AuthTokenSynchronousRefreshBugFix
Jun 18, 2026
Merged

dataconnect(fix): fix potential infinite loop when Auth and/or App Check tokens refreshed#8319
dconeybe merged 2 commits into
mainfrom
dconeybe/dataconnect/AuthTokenSynchronousRefreshBugFix

Conversation

dconeybe commented Jun 18, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

This PR resolves a potential infinite loop of cancellations and retries in Data Connect that could occur in DataConnectCredentialsTokenManager if an auth or App Check token change notification was triggered synchronously during an active token fetch. Instead of immediately cancelling the active job when a token change is detected, the manager now awaits its completion and inspects the result to determine if the expected token has already been retrieved.

Highlights

  • Awaits active jobs instead of cancelling: Refactored onTokenChanged() to await the in-flight getToken() job rather than cancelling it immediately. This prevents a cascade of cancellation-retry loops when token notifications are synchronous.
  • Reuse of successful fetches: If the completed job returns the newly notified token, no further calls are made, reducing the total calls to the provider's getAccessToken() to exactly 1.
  • Updated unit tests: Replaced the cancellation-behavior test with a synchronous-refresh test to verify that calling onTokenChanged during a fetch doesn't result in redundant provider calls.
Changelog
  • CHANGELOG.md
    • Added a entry for the infinite loop fix when Auth/App Check tokens are refreshed.
  • DataConnectCredentialsTokenManager.kt
    • Removed the NewToken retry exception class.
    • Refactored onTokenChanged() to launch a coroutine that awaits the active job and evaluates the retrieved token against the new token, skipping the retry if they match.
  • DataConnectAuthUnitTest.kt
    • Removed onTokenChanged() should cancel in-flight getToken() requests and retry.
    • Added onTokenChanged() called synchronously from getToken() to verify synchronous notifications don't trigger redundant calls.
    • Cleaned up unused imports.

…f onTokenChanged() is called synchronously from getToken() [no ci]

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request addresses an infinite loop issue that occurred when Auth and/or App Check tokens were refreshed. It refactors the onTokenChanged method in DataConnectCredentialsTokenManager to await the active token job and verify if the new token is actually different before triggering a new token retrieval, rather than unconditionally cancelling and retrying. Unit tests were updated accordingly, including a new test verifying synchronous calls. The review feedback suggests simplifying a nested fold structure in the refactored onTokenChanged method using Kotlin's safe call and Elvis operators to improve readability.

dconeybe marked this pull request as ready for review June 18, 2026 00:59

stephenarosaj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

dconeybe merged commit c9224d1 into main Jun 18, 2026
49 checks passed
dconeybe deleted the dconeybe/dataconnect/AuthTokenSynchronousRefreshBugFix branch June 18, 2026 16:58
github-actions Bot mentioned this pull request Jun 19, 2026
firebase locked and limited conversation to collaborators Jul 18, 2026
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL