⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@cloudwebrtc
Copy link
Contributor

@cloudwebrtc cloudwebrtc commented Jan 27, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved publisher connection stability by centralizing connection handling, adding a single awaited connection flow with automatic reset on failure, and ensuring connections are cleared and retried after restarts or when peer connection states become closed/failed/disconnected. This reduces race conditions and improves reliability for publishing and data sending paths.

@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

Adds a cached in-progress publisher connection Future and a new internal ensurePublisherConnected() method in Engine to centralize and reuse publisher connection attempts; replaces direct _publisherEnsureConnected() calls and resets the cache when the RTCPeerConnection enters Closed, Failed, or Disconnected states.

Changes

Cohort / File(s) Summary
Publisher connection logic
lib/src/core/engine.dart
Added _publisherConnectionFuture: Future<void>?; added @internal Future<void> ensurePublisherConnected() that caches and awaits publisher connection attempts and clears on error; replaced _publisherEnsureConnected() call sites with ensurePublisherConnected(); reset cache when RTCPeerConnection state becomes Closed/Failed/Disconnected and on full restart.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 I hop, I stash one Future bright,
One handshake stored to avoid a fight,
When wires fray and silence calls,
I clear my cache and mend the halls,
Little rabbit reconnects through night.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: debounce for ensurePublisherConnected' directly describes the main change—implementing debouncing logic via the new ensurePublisherConnected() method and _publisherConnectionFuture caching mechanism to prevent duplicate publisher connection attempts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch duan/debounce-for-publisher-connection-ensure

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f1741f and 7eee1b6.

📒 Files selected for processing (1)
  • lib/src/core/engine.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Build for Flutter Web WASM
  • GitHub Check: Build for Flutter iOS
  • GitHub Check: Build for Flutter Linux
  • GitHub Check: Build for Flutter Windows
  • GitHub Check: Build for Flutter macOS
  • GitHub Check: Build for Flutter Web
  • GitHub Check: Build for Flutter Android
🔇 Additional comments (6)
lib/src/core/engine.dart (6)

168-169: LGTM!

The field declaration is appropriate for caching the in-progress publisher connection Future.


506-515: LGTM!

The implementation correctly addresses the previous review feedback by resetting _publisherConnectionFuture to null on error, allowing subsequent retry attempts. The ??= operator ensures that concurrent calls share the same in-progress Future (debounce behavior).


413-413: LGTM!

Correctly uses the new centralized ensurePublisherConnected() method to benefit from debounced connection attempts.


649-655: LGTM!

Correctly resets the cached Future when the publisher connection enters terminal or failure states. This ensures fresh connection attempts after connection loss, aligning with the existing reconnection handling below.


1132-1133: LGTM!

Correctly resets _publisherConnectionFuture when tearing down the old publisher during a full restart. This addresses the previous review feedback and ensures the new publisher gets a fresh connection attempt.


1155-1158: LGTM!

Correctly uses ensurePublisherConnected() to re-establish the publisher connection after a full restart when publishing was previously active.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@lib/src/core/engine.dart`:
- Around line 506-510: ensurePublisherConnected currently caches the future in
_publisherConnectionFuture but never clears it if _publisherEnsureConnected()
throws or times out, causing permanent failure; modify ensurePublisherConnected
to assign _publisherConnectionFuture = _publisherEnsureConnected() as now, then
await it inside a try/catch, and in the catch block reset
_publisherConnectionFuture to null before rethrowing the error so subsequent
calls can retry; reference functions/fields: ensurePublisherConnected,
_publisherConnectionFuture, and _publisherEnsureConnected.
- Around line 1148-1150: Cached publisher connection future
_publisherConnectionFuture can remain completed after restartConnection()
causing ensurePublisherConnected() to skip renegotiation; when
disposing/recreating the publisher inside restartConnection() clear/reset
_publisherConnectionFuture (set to null or a fresh completer) so
ensurePublisherConnected() will recreate the connection for the new publisher
instance; update restartConnection() teardown path where the old publisher is
disposed to reset _publisherConnectionFuture before new publisher creation.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db929a3 and 8f1741f.

📒 Files selected for processing (1)
  • lib/src/core/engine.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Build for Flutter Android
  • GitHub Check: Build for Flutter Web WASM
  • GitHub Check: Build for Flutter Linux
  • GitHub Check: Build for Flutter Windows
  • GitHub Check: Build for Flutter macOS
  • GitHub Check: Build for Flutter iOS
  • GitHub Check: Build for Flutter Web
🔇 Additional comments (3)
lib/src/core/engine.dart (3)

168-168: LGTM: cached in-flight publisher connection state.

The field addition is clear and well-scoped for debouncing.


411-423: LGTM: avoid sending before publisher is connected.

Good guard to ensure the publisher transport is ready when subscriber is primary.


643-650: LGTM: cache reset on disconnected/failed/closed states.

This keeps the memoized future aligned with connection lifecycle.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Contributor

@xianshijing-lk xianshijing-lk left a comment

Choose a reason for hiding this comment

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

please address the ai bot comments, I found it pretty useful.

@cloudwebrtc cloudwebrtc merged commit 57c8d42 into main Feb 3, 2026
16 checks passed
@cloudwebrtc cloudwebrtc deleted the duan/debounce-for-publisher-connection-ensure branch February 3, 2026 02:26
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.

3 participants