Skip to content

Fix: Force reconnection in case of stale connection. - #21492

Merged
antobinary merged 3 commits into
bigbluebutton:v3.0.x-releasefrom
Tainan404:retry-reconnection
Oct 29, 2024
Merged

antobinary merged 3 commits into
bigbluebutton:v3.0.x-releasefrom
Tainan404:retry-reconnection

Conversation

@Tainan404

Copy link
Copy Markdown
Member

What does this PR do?

This PR intends to make the client terminates the connection when notice that it's stale, the own apollo client tries to reconnect when the shouldRetry returns true, I also set a configurable amount of time to try the reconnection.

Closes Issue(s)

Closes #21062

How to test

Join the client and switch network or turn on/off a VPN.

@coderabbitai

coderabbitai Bot commented Oct 22, 2024 •

Copy link
Copy Markdown
Contributor

Walkthrough

The pull request introduces several modifications primarily focused on improving the connection management capabilities of the BigBlueButton HTML5 client. A new property, terminateAndRetryConnection, of type number has been added to the App interface within the MeetingClientSettings. This addition is reflected in the configuration file settings.yml, where it is set to a timeout value of 30,000 milliseconds. In the ConnectionManager component, a reference terminateTimeoutRef has been introduced to manage timeouts for WebSocket connections, along with a variable terminateAndRetry that retrieves the newly added setting. The useEffect hook has been updated to utilize these changes, allowing for more effective handling of connection timeouts and improved error handling, specifically addressing connection errors with code 4403. Overall, these changes aim to enhance the client’s ability to manage connections, particularly during network switches.

Assessment against linked issues

Objective Addressed Explanation
Improve connection management during network switches (Issue #21062) ✅
Ensure client can re-establish connection or fail definitively (Issue #21062) ✅

Possibly related PRs

  • Fix: close event emitting a terminal error #21299: This PR modifies the ConnectionManager component, which is directly related to the changes made in the main PR regarding connection management and the new terminateAndRetryConnection property, enhancing the handling of WebSocket connections.

Suggested reviewers

  • antobinary
  • prlanzarin

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (2)
bigbluebutton-html5/imports/ui/Types/meetingClientSettings.ts (1)

102-102: LGTM. Consider adding JSDoc comment for clarity.

The addition of terminateAndRetryConnection property aligns well with the PR objective of enhancing stale connection handling. The property name is clear and follows the existing naming conventions.

Consider adding a JSDoc comment to provide more context about this property, such as:

/**
 * Time limit in milliseconds for terminating and retrying a stale connection.
 */
terminateAndRetryConnection: number;
bigbluebutton-html5/private/config/settings.yml (1)

89-89: Minor: Remove trailing space.

There's a trailing space at the end of line 89. While this doesn't affect functionality, it's good practice to remove it for consistency.

You can remove the trailing space as follows:

-    # and a new connection is attempted 
+    # and a new connection is attempted
🧰 Tools
🪛 yamllint

[error] 89-89: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a017cc2 and 8db0b0e.

📒 Files selected for processing (3)
  • bigbluebutton-html5/imports/ui/Types/meetingClientSettings.ts (1 hunks)
  • bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx (2 hunks)
  • bigbluebutton-html5/private/config/settings.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
bigbluebutton-html5/private/config/settings.yml

[error] 89-89: trailing spaces

(trailing-spaces)

🔇 Additional comments (3)
bigbluebutton-html5/private/config/settings.yml (1)

88-90: LGTM! New configuration option added for connection management.

The new terminateAndRetryConnection setting aligns well with the PR objectives to enhance the client's ability to handle stale connections. The 30-second timeout (30,000 ms) seems reasonable for attempting to reconnect.

🧰 Tools
🪛 yamllint

[error] 89-89: trailing spaces

(trailing-spaces)

bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx (2)

89-89: Specify the correct type for terminateTimeoutRef

The setTimeout function in browser environments returns a number, so using useRef<number>() is appropriate. However, to ensure type safety and accommodate environments where setTimeout might return different types (like NodeJS.Timeout), consider explicitly typing terminateTimeoutRef as React.MutableRefObject<number | undefined>.


124-124: Handle potential undefined terminateTimeoutRef.current

When calling clearTimeout, ensure that terminateTimeoutRef.current is defined to avoid potential runtime issues.

const [terminalError, setTerminalError] = React.useState<string | Error>('');
const [MeetingSettings] = useMeetingSettings();
const enableDevTools = MeetingSettings.public.app.enableApolloDevTools;
const terminateAndRetry = MeetingSettings.public.app.terminateAndRetryConnection;

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.

⚠️ Potential issue

Provide a default value for terminateAndRetry

If MeetingSettings.public.app.terminateAndRetryConnection is undefined, terminateAndRetry will be undefined, which may cause issues with setTimeout. To ensure reliable behavior, provide a default value.

Apply this diff to set a default value:

-const terminateAndRetry = MeetingSettings.public.app.terminateAndRetryConnection;
+const terminateAndRetry = MeetingSettings.public.app.terminateAndRetryConnection ?? 30_000; // Default to 30 seconds
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const terminateAndRetry = MeetingSettings.public.app.terminateAndRetryConnection;
const terminateAndRetry = MeetingSettings.public.app.terminateAndRetryConnection ?? 30_000; // Default to 30 seconds

Comment on lines +113 to +117
terminateTimeoutRef.current = window.setTimeout(() => {
// The apollo client will try to reconnect after the connection is terminated
// if the option to reconnect is true
apolloContextHolder.getLink().terminate();
}, terminateAndRetry);

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.

⚠️ Potential issue

Ensure terminateTimeoutRef is cleared on component unmount

To prevent potential memory leaks, ensure that terminateTimeoutRef.current is cleared when the component unmounts.

Apply this diff to add cleanup:

 useEffect(() => {
   const interval = setInterval(() => {
     // existing code
   }, 5_000);
   return () => {
     clearInterval(interval);
+    if (terminateTimeoutRef.current !== undefined) {
+      clearTimeout(terminateTimeoutRef.current);
+    }
   };
 }, []);

Committable suggestion was skipped due to low confidence.


⚠️ Potential issue

Prevent multiple timeouts from being scheduled

When the condition remains true over multiple intervals, multiple timeouts could be scheduled without clearing the previous ones. This can lead to unexpected behavior. Check if a timeout is already set before scheduling a new one.

Apply this diff to prevent redundant timeouts:

 if ((tsNow - tsLastMessageRef.current > boundary.current) && connectionStatus.getServerIsResponding()) {
+  if (!terminateTimeoutRef.current) {
     connectionStatus.setServerIsResponding(false);
     terminateTimeoutRef.current = window.setTimeout(() => {
       // The apollo client will try to reconnect after the connection is terminated
       // if the option to reconnect is true
       apolloContextHolder.getLink().terminate();
+      terminateTimeoutRef.current = undefined;
     }, terminateAndRetry);
+  }
 } else if ((tsNow - tsLastPingMessageRef.current > boundary.current) && connectionStatus.getPingIsComing()) {

Committable suggestion was skipped due to low confidence.

@antobinary antobinary added this to the Release 3.0 milestone Oct 22, 2024
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai 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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
bigbluebutton-html5/imports/ui/core/initial-values/meetingClientSettings.ts (1)

6-6: LGTM! Consider adding a comment for clarity.

The addition of terminateAndRetryConnection aligns well with the PR objectives for improving connection management. The 30-second timeout seems reasonable for terminating and retrying connections.

Consider adding a brief comment to explain the purpose and unit of measurement for this setting:

+  // Timeout in milliseconds for terminating and retrying stale connections
   terminateAndRetryConnection: 30000,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8db0b0e and e7a83d2.

📒 Files selected for processing (2)
  • bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx (2 hunks)
  • bigbluebutton-html5/imports/ui/core/initial-values/meetingClientSettings.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx
🧰 Additional context used

@github-actions

Copy link
Copy Markdown

Automated tests Summary

✅ All the CI tests have passed!

@gustavotrott

Copy link
Copy Markdown
Contributor

30 seconds seems to align with the SFU re-connection! 👍️

@ramonlsouza
ramonlsouza requested review from antonbsa and removed request for ramonlsouza October 24, 2024 13:03
@antobinary
antobinary merged commit f530404 into bigbluebutton:v3.0.x-release Oct 29, 2024
ramonlsouza pushed a commit that referenced this pull request Oct 5, 2026
The watchdog added in #21492 arms a timer to terminate and reconnect the
GraphQL websocket when no message arrives for 15 s. It only arms the timer
when the ref is empty, but the ref was never cleared: not when messages
resume, nor when the timer fires. So the forced reconnect worked once per
page load. Every later stale period left the client silent until the user
reloaded.

Clear the ref in both places so every stale period gets its own timer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
antobinary pushed a commit that referenced this pull request Oct 6, 2026
The watchdog added in #21492 arms a timer to terminate and reconnect the
GraphQL websocket when no message arrives for 15 s. It only arms the timer
when the ref is empty, but the ref was never cleared: not when messages
resume, nor when the timer fires. So the forced reconnect worked once per
page load. Every later stale period left the client silent until the user
reloaded.

Clear the ref in both places so every stale period gets its own timer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 979a522)
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.0] Switching networks causes persistent server disconnection (intermittent)

4 participants