Add automatic reconnection with exponential backoff#1246
Conversation
…backoff Add automatic reconnection support for MoQ clients. Reconnect spawns a background tokio task that connects, waits for session close, then reconnects with configurable exponential backoff (default: 1s/2x/30s). Dropping the handle or calling close() aborts the background task. https://claude.ai/code/session_01BTTwQv5UW7yFAuYiKBPM8X
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 1 minutes and 15 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
WalkthroughThis change introduces configurable exponential-backoff reconnection functionality to the MOQ native client. A new 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rs/moq-native/src/reconnect.rs (1)
70-83: Consider adding a delay or jitter after session close.When a session closes (lines 74-75), reconnection happens immediately without any delay. If the server accepts connections but quickly terminates sessions (e.g., due to overload or misconfiguration), this could cause rapid reconnection attempts. Consider adding a small base delay or jitter after clean session closure.
♻️ Optional: Add minimal delay after session close
Ok(session) => { tracing::info!(%url, "connected"); delay = backoff.initial; let _ = session.closed().await; tracing::warn!(%url, "session closed, reconnecting"); + // Small delay before reconnecting to avoid hammering server + tokio::time::sleep(Duration::from_millis(100)).await; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@rs/moq-native/src/reconnect.rs` around lines 70 - 83, The Ok branch for client.connect handles clean session closure immediately restarting the loop (involving session.closed()). After session.closed().await, introduce a short sleep with jitter instead of immediate reconnect: compute a small base delay (e.g., backoff.initial or a configured min_close_delay) add randomized jitter, await tokio::time::sleep on that duration, and then reset delay = backoff.initial as currently done; this change is localized to the Ok(session) arm around session.closed() to prevent tight reconnect loops when the server is closing sessions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@rs/moq-native/src/reconnect.rs`:
- Around line 70-83: The Ok branch for client.connect handles clean session
closure immediately restarting the loop (involving session.closed()). After
session.closed().await, introduce a short sleep with jitter instead of immediate
reconnect: compute a small base delay (e.g., backoff.initial or a configured
min_close_delay) add randomized jitter, await tokio::time::sleep on that
duration, and then reset delay = backoff.initial as currently done; this change
is localized to the Ok(session) arm around session.closed() to prevent tight
reconnect loops when the server is closing sessions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b248db0b-bebc-4639-ab66-d49ac85d474f
📒 Files selected for processing (3)
rs/moq-native/src/client.rsrs/moq-native/src/lib.rsrs/moq-native/src/reconnect.rs
- Add optional `timeout` to Backoff (resets after each successful connection, gives up with error when exceeded) - Add `closed().await` to Reconnect (resolves on timeout or close) - Migrate moq-cli, moq-clock, moq-boy, and hang examples to use `reconnect()` instead of `connect()` - Add `timeout` and `closed` promise to JS Reload class https://claude.ai/code/session_01BTTwQv5UW7yFAuYiKBPM8X
Summary
This PR adds automatic reconnection functionality to the MOQ native client, allowing it to maintain persistent connections with exponential backoff retry logic.
Key Changes
New
reconnectmodule: ImplementsReconnecthandle andBackoffconfiguration for managing automatic reconnection attemptsBackoffstruct with configurable initial delay (default 1s), multiplier (default 2x), and maximum delay (default 30s)Reconnecthandle: Spawns a background tokio task that:close()Client integration:
backofffield toClientConfigwith CLI and serde supportbackofffield toClientstructClient::reconnect()method to start the background reconnection loopImplementation Details
tokio::task::AbortHandlefor clean task cancellationhttps://claude.ai/code/session_01BTTwQv5UW7yFAuYiKBPM8X