dataconnect(change): Add 15 second grace before disconnecting a streaming connection with the backend#8481
Conversation
… allow a grace period before killing the active connection
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a 15-second grace period before closing the realtime streaming connection after the last subscriber unsubscribes, replacing the previous behavior of closing it immediately. It also adds comprehensive unit tests to verify connection reuse within the grace period and connection recreation after it expires. The reviewer feedback suggests extracting the hardcoded 15-second duration (15,000 milliseconds) into a shared named constant to avoid magic numbers and ensure consistency between the implementation and the test suite.
Using Gemini Code AssistThe 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
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 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. |
…ather than hardcoding 15 seconds to improve readabiltiy of the test code.
📝 PRs merging into main branchOur 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. |
…alive for exactly the grace period after last subscriber unsubscribes" by ignoring spurious "cancel" StreamRequest
This PR adds a 15-second grace period before closing a Firebase Data Connect realtime streaming connection after the last subscriber unsubscribes, rather than closing it immediately. This helps avoid connection flapping and reduces backend load during rapid unsubscription/resubscription transitions, such as during activity or screen navigation.
Highlights
DataConnectBidiConnectStreamto use a 15-second stop timeout (SharingStarted.WhileSubscribed) on the shared flow, delaying physical connection closure when the last subscriber unsubscribes.QuerySubscriptionImplUnitTestto verify that the connection remains open for exactly the grace period, that re-subscribing within the grace period reuses the connection, and that re-subscribing after the grace period establishes a new connection.CHANGELOG.md.Changelog
SharingStarted.WhileSubscribedwith astopTimeoutMillisof 15,000 milliseconds (15 seconds) to delay connection closure when subscriptions are cancelled.CONNECTION_GRACE_PERIOD_MSconstant.