Skip to content

dataconnect(change): add exponential backoff in realtime query subscriptions upon disconnecting from the server#8381

Open
dconeybe wants to merge 7 commits into
mainfrom
dconeybe/dataconnect/backoff
Open

dataconnect(change): add exponential backoff in realtime query subscriptions upon disconnecting from the server#8381
dconeybe wants to merge 7 commits into
mainfrom
dconeybe/dataconnect/backoff

Conversation

@dconeybe

@dconeybe dconeybe commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Introduce exponential backoff retry strategy for Data Connect realtime query subscriptions when they disconnect or fail to connect. When connection failures occur, the client backs off progressively before retrying, but resets the delay on successful messages, immediate retry triggers, or when a new subscription is registered.

Highlights

  • Exponential Backoff Strategy: Replaced the previous fixed 1-second retry delay with an exponential backoff calculator (RetryBackoffCalculator) capped at 10 minutes (600,000ms), using a multiplier of 1.75.
  • Subscription Wakeup: Configured new query subscriptions to trigger an immediate retry and reset the backoff calculation, avoiding unnecessary waiting when a user actively requests new data.
  • ConflatedSignal Reset Capability: Added a clear() method to ConflatedSignal to allow discarding pending signals, which is utilized to manage retry and wakeup events cleanly.
  • Comprehensive Testing: Added unit tests validating retry intervals, backoff scaling, signal clearing, and the immediate wakeup behavior when new subscribers join.
Changelog
  • CHANGELOG.md
    • Added a changelog entry noting that realtime query subscriptions now retry connecting using an exponential backoff strategy.
  • RetryBackoffCalculator.kt
    • Introduced a new internal thread-safe class to calculate backoff retry delays starting at 1000ms with a 1.75 multiplier and capped at 600,000ms.
  • ConflatedSignal.kt
    • Added a clear() method to discard any pending signals, causing subsequent calls to await to suspend until a new signal is emitted.
  • DataConnectBidiConnectStream.kt
    • Replaced the hardcoded 1-second retry delay with the new RetryBackoffCalculator and a ConflatedSignal event to handle retries and immediate wakeup actions.
    • Resets the backoff upon new subscriptions or successful message streams.
    • Added testing callback registration methods to allow validation of backoff timings.
  • RetryBackoffCalculatorUnitTest.kt
    • Added unit tests verifying RetryBackoffCalculator next value progression, max value ceiling, reset functionality, and thread-safety under concurrent access.
  • ConflatedSignalUnitTest.kt
    • Added unit tests verifying the correctness of the new clear() method.
  • QuerySubscriptionImplUnitTest.kt
    • Added unit tests verifying that new subscriptions reset backoff, that initial and subsequent connection failures follow the expected retry delays, and that healthy/immediate retries reset backoff state.

@gemini-code-assist

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.

@dconeybe

dconeybe commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist 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.

Code Review

This pull request implements an exponential backoff strategy for retrying realtime query subscription connections. It introduces a thread-safe RetryBackoffCalculator class to compute backoff durations starting at 1000ms with a 1.75 multiplier up to a maximum of 600,000ms. It also adds a clear() method to ConflatedSignal to discard pending signals, and updates DataConnectBidiConnectStream to utilize these components. Comprehensive unit tests have been added to verify the backoff calculation, signal clearing, and overall retry behaviors under various scenarios. I have no feedback to provide as there are no review comments.

@github-actions

github-actions Bot commented Jul 2, 2026

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant