Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internal-plugin-mercury): missing maxRetries property in mercury plugin config #3969

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

k-wasniowski
Copy link
Contributor

@k-wasniowski k-wasniowski commented Nov 13, 2024

COMPLETES #SPARK-548638

This pull request addresses

This PR addresses the issue that manifests itself as an infinite loop of reconnection. It occurs if during the meeting reconnection, JS-SDK is getting stuck on the mercury socket reconnection.

by making the following changes

Add missing configuration which specifies how many reconnection attempts we can do before giving up, otherwise we will try to connect infinitly.

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

Tested with JS-SDK sample app, disconnecting client in various ways to identify if everytime, meeting will give up reconnections after 5 times.

I certified that

  • I have read and followed contributing guidelines

  • I discussed changes with code owners prior to submitting this pull request

  • I have not skipped any automated checks

  • All existing and new tests passed

  • I have updated the documentation accordingly


Make sure to have followed the contributing guidelines before submitting.

Summary by CodeRabbit

  • New Features

    • Updated the connection retry logic in the Mercury plugin, now allowing up to 5 retries before failing.
    • Introduced a new configuration option for managing connection retries with a default value of 5.
  • Documentation

    • Revised the README to reflect the changes in configuration options related to connection retries.

Copy link

coderabbitai bot commented Nov 13, 2024

Walkthrough

The pull request updates the @webex/internal-plugin-mercury package by modifying the connection retry configuration. The maxRetries parameter is changed from 0 to 5, allowing the Mercury service to attempt five reconnection attempts before failing. This adjustment is reflected in the README and introduces a new property in the configuration file that retrieves its value from an environment variable, defaulting to 5 if not set.

Changes

File Path Change Summary
packages/@webex/internal-plugin-mercury/README.md Updated maxRetries parameter from 0 to 5 in configuration options.
packages/@webex/internal-plugin-mercury/src/config.js Added maxRetries property to the mercury object, retrieving value from MERCURY_MAX_RETRIES.

Possibly related PRs

  • fix: add ice candidates gathering timeout config #3951: The addition of the iceCandidatesTimeout parameter in the createMediaConnection method relates to enhancing connection handling, similar to how the maxRetries parameter in the main PR improves connection retry logic.

Suggested reviewers

  • marcin-bazyl
  • szotrabh
  • SomeBody16

Poem

🐰 In the meadow where bunnies play,
Connections now retry five times a day!
With maxRetries set, we hop with glee,
No more lone failures, just joy and spree!
So let’s cheer for the changes, oh what a sight,
In the world of Mercury, everything’s bright! 🌼


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.

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-3969.d3m3l2kee0btzx.amplifyapp.com

@k-wasniowski k-wasniowski added the validated If the pull request is validated for automation. label Nov 13, 2024
@k-wasniowski k-wasniowski force-pushed the fix-do-cleanup-before-reconnect branch 2 times, most recently from 20f23b5 to c798eba Compare November 14, 2024 07:11
@k-wasniowski k-wasniowski marked this pull request as ready for review November 14, 2024 08:34
@k-wasniowski k-wasniowski requested review from a team as code owners November 14, 2024 08:35
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: 0

🧹 Outside diff range and nitpick comments (2)
packages/@webex/internal-plugin-mercury/src/config.js (1)

40-44: Consider documenting retry behavior in logs.

While the configuration is solid, it would be valuable for debugging and monitoring to ensure that retry attempts are properly logged.

Consider:

  1. Logging each retry attempt with current count
  2. Logging when max retries are exhausted
  3. Adding metrics/telemetry for retry-related events
packages/@webex/internal-plugin-mercury/README.md (1)

60-63: Consider enhancing the retry mechanism documentation

While the parameters are documented, the documentation could be more helpful with:

  1. An explanation of how the exponential backoff works
  2. Examples of retry scenarios and timing
  3. Clarification of why initialConnectionMaxRetries defaults to 0 while maxRetries defaults to 5

Example addition:

 - `maxRetries` - the number of times it will retry before error. Default: 5
 - `initialConnectionMaxRetries` - the number of times it will retry before error on the first connection. Once a connection has been established, any further connection attempts will use `maxRetries`. Default: 0
 - `backoffTimeMax` - The maximum time between connection attempts in ms. Default: 32000
 - `backoffTimeReset` - The time before the first retry in ms. Default: 1000
+
+### Retry Behavior Example
+
+When a connection fails, the system will:
+1. Wait `backoffTimeReset` (1000ms)
+2. Attempt reconnection
+3. If failed, wait twice the previous wait time (exponential backoff)
+4. Repeat until either:
+   - Connection succeeds
+   - `maxRetries` (5) is reached
+   - Wait time would exceed `backoffTimeMax` (32000ms)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 397373d and 053265f.

📒 Files selected for processing (2)
  • packages/@webex/internal-plugin-mercury/README.md (1 hunks)
  • packages/@webex/internal-plugin-mercury/src/config.js (1 hunks)
🔇 Additional comments (4)
packages/@webex/internal-plugin-mercury/src/config.js (2)

40-44: LGTM! The maxRetries configuration is well-implemented.

The implementation follows the established patterns in the file and effectively addresses the infinite reconnection loop issue. The default value of 5 retries provides a good balance between reliability and fail-fast behavior.


40-44: Verify integration with other timeout configurations.

The new maxRetries works in conjunction with existing backoff configurations. Let's verify the interaction.

✅ Verification successful

Let me gather more specific information about the retry and backoff implementation in Mercury.


Integration with timeout configurations verified successfully

The maxRetries configuration works correctly with the backoff strategy:

  • It's properly integrated with the exponential backoff implementation using backoff.ExponentialStrategy
  • Works in conjunction with backoffTimeMax (32000ms) and backoffTimeReset (1000ms)
  • The retry mechanism is well-tested, including edge cases for both initial connection and reconnection scenarios
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential interactions between retry logic and other timeout configurations

# Search for any retry-related logic that might interact with this configuration
rg -l 'retry|reconnect' --type js

# Look for backoff time usage in conjunction with connection attempts
ast-grep --pattern 'backoffTime(Max|Reset)'

Length of output: 2213


Script:

#!/bin/bash
# Check Mercury's implementation for retry and backoff logic
rg -A 10 "maxRetries" packages/@webex/internal-plugin-mercury/src/mercury.js

# Look for backoff time configuration and usage
rg "backoff" packages/@webex/internal-plugin-mercury/src/

# Check the test cases to understand the retry behavior
rg "maxRetries" packages/@webex/internal-plugin-mercury/test/

Length of output: 3641

packages/@webex/internal-plugin-mercury/README.md (2)

60-60: LGTM: maxRetries default value updated to prevent infinite loops

The change from unlimited retries to a maximum of 5 retries aligns well with the PR objective of preventing infinite reconnection loops.


60-63: Verify configuration parameters match implementation

Let's ensure the documented defaults match the actual implementation.

✅ Verification successful

Let me search for the other configuration parameters to complete the verification.


Documentation matches implementation

The documented configuration parameters and their default values are accurately reflected in the implementation:

  • maxRetries: Default 5 (config.js: process.env.MERCURY_MAX_RETRIES || 5)
  • initialConnectionMaxRetries: Default 0 (not set in config, used conditionally in mercury.js)
  • backoffTimeMax: Default 32000 (config.js: process.env.MERCURY_BACKOFF_TIME_MAX || 32000)
  • backoffTimeReset: Default 1000 (config.js: process.env.MERCURY_BACKOFF_TIME_RESET || 1000)

All parameters are actively used in the codebase for connection retry logic and backoff timing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the configuration parameters in the source code
echo "Searching for maxRetries configuration..."
rg -A 5 "MERCURY_MAX_RETRIES|maxRetries" packages/@webex/internal-plugin-mercury/

echo "Searching for retry-related configuration..."
ast-grep --pattern 'const $_ = {
  $$$
  maxRetries: $_,
  $$$
}'

Length of output: 5931


Script:

#!/bin/bash
# Search for backoff-related configuration
echo "Searching for backoff configuration..."
rg "backoffTimeMax|backoffTimeReset" packages/@webex/internal-plugin-mercury/

echo "Searching for initialConnectionMaxRetries..."
rg "initialConnectionMaxRetries" packages/@webex/internal-plugin-mercury/src/

Length of output: 3118

@k-wasniowski k-wasniowski changed the title fix: stop stats analyzer when reconnecting, and do not allow infinite loop of reconnections fix(internal-plugin-mercury): missing maxRetries property in mercury plugin config Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validated If the pull request is validated for automation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant