Skip to content

feat(data-connect): add intelligent reconnection to streaming transport #9893

Draft
stephenarosaj wants to merge 6 commits intopasta/mainfrom
pasta/arancini
Draft

feat(data-connect): add intelligent reconnection to streaming transport #9893
stephenarosaj wants to merge 6 commits intopasta/mainfrom
pasta/arancini

Conversation

@stephenarosaj
Copy link
Copy Markdown
Contributor

@stephenarosaj stephenarosaj commented Apr 24, 2026

Description

✨ Implemented intelligent reconnection with exponential backoff and lifecycle disposal for the Firebase Data Connect streaming transport.

Changes

  • Added exponential backoff and jitter to AbstractDataConnectStreamTransport.
  • Added environment hooks (onOnline, onVisibilityChange) for reconnect triggers.
  • Refactored onStreamClose to handle idle disconnects and cancel close timeouts.
  • Added dispose() method to clean up listeners, timers, and close connection.
  • Failed pending mutations on disconnect to maintain safety.
  • Updated transportManager.test.ts to simulate terminal failure using rejectAllRequests directly.

Testing

  • Added 6 unit tests for reconnection in streamTransport.test.ts.
  • Added 1 unit test for dispose() in streamTransport.test.ts.
  • Updated existing tests to handle strict checks and Node environment limitations.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: d0ce41a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 automatic reconnection logic with exponential backoff for the Data Connect stream transport. Key changes include the addition of browser event listeners (online and visibilitychange) to trigger immediate reconnection attempts, the introduction of a backoff mechanism for unexpected disconnects, and logic to re-trigger active subscriptions and queries upon reconnection. Pending mutations are now explicitly rejected when a stream disconnects unexpectedly. Feedback focuses on preventing memory leaks by unregistering browser event listeners and ensuring that the idle timeout is cancelled during unexpected disconnects to avoid conflicting timers.

Comment thread packages/data-connect/src/network/stream/streamTransport.ts
Comment thread packages/data-connect/src/network/stream/streamTransport.ts
@stephenarosaj
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 automatic reconnection logic for the Data Connect stream transport, incorporating exponential backoff with jitter and integration with browser events like online/offline and visibility changes to trigger reconnections. It also introduces a dispose method for resource cleanup and refactors timeout-related naming for better clarity. A review comment correctly identifies a JSDoc error in the cleanupBrowserEventListeners method, which incorrectly describes the function as registering rather than unregistering event listeners.

}

/**
* Register event listeners for browser-specific events like online/offline and visibility changes.
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.

medium

The JSDoc comment for cleanupBrowserEventListeners incorrectly states that it registers event listeners, but the method actually removes them. Please update the comment to reflect the correct behavior.

  /**
   * Unregister event listeners for browser-specific events like online/offline and visibility changes.
   */

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.

1 participant