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

balancer: fix clients not being removed from balancer context on disconnect #1212

Merged
merged 2 commits into from
Jan 12, 2024

Conversation

dyc3
Copy link
Owner

@dyc3 dyc3 commented Jan 11, 2024

Summary by CodeRabbit

  • Bug Fixes
    • Improved client management by enabling the removal of clients from the active list.

Copy link
Contributor

coderabbitai bot commented Jan 11, 2024

Walkthrough

The recent update involves a modification to the load balancer's client management system, specifically introducing functionality to remove a client from the internal tracking map. This change suggests an enhancement in the way the balancer maintains and updates its list of active clients.

Changes

File Path Change Summary
crates/ott-balancer/src/balancer.rs Added the removal of a client from the self.clients map.

Poem

In the code where clients dance,
A rabbit hopped and took a chance.
With a 🎩 and a hop, it made a stance,
"Goodbye, dear client," it said, with a glance.

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8881023 and f8fbac8.
Files selected for processing (1)
  • crates/ott-balancer/src/balancer.rs (1 hunks)
Additional comments: 1
crates/ott-balancer/src/balancer.rs (1)
  • 212-218: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-214]

While the specific change to remove_client is correct, it's important to review the entire flow of client disconnection to ensure that there are no other places where the client should be removed from self.clients but isn't. This includes checking all the paths that lead to a client disconnection and ensuring that remove_client is called appropriately in each case.

crates/ott-balancer/src/balancer.rs Show resolved Hide resolved
Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5d7baad) 61.5318% compared to head (3b3efe0) 61.5318%.

Additional details and impacted files
@@             Coverage Diff             @@
##             master      #1212   +/-   ##
===========================================
  Coverage   61.5318%   61.5318%           
===========================================
  Files           115        115           
  Lines          9322       9322           
  Branches       1141       1141           
===========================================
  Hits           5736       5736           
  Misses         3586       3586           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cypress bot commented Jan 11, 2024

Passing run #802 ↗︎

0 71 1 0 Flakiness 0

Details:

Merge 3b3efe0 into 5d7baad...
Project: OpenTogetherTube Commit: 09e2146ad3 ℹ️
Status: Passed Duration: 03:47 💡
Started: Jan 11, 2024 3:25 PM Ended: Jan 11, 2024 3:29 PM

Review all test suite changes for PR #1212 ↗︎

@dyc3 dyc3 changed the title balancer: fix clients not being removed from balancer context on disconnect possibly related to #1207? balancer: fix clients not being removed from balancer context on disconnect Jan 11, 2024
Copy link
Contributor

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5d7baad and 3b3efe0.
Files selected for processing (1)
  • crates/ott-balancer/src/balancer.rs (2 hunks)
Additional comments: 2
crates/ott-balancer/src/balancer.rs (2)
  • 215-215: The change to remove the client from the self.clients map upon disconnection is crucial for maintaining the integrity of the balancer's state. It's good to see that this fix has been implemented. However, it's important to ensure that this change is covered by unit tests to verify its correctness.
Verification successful

The provided script output confirms that the test_clients_add_remove function in the balancer.rs file includes logic to test the removal of a client from the BalancerContext. The test adds a client, asserts that the client is in the context, then removes the client and asserts that the client is no longer in the context. This indicates that the unit test covers the scenario where a client is removed, which aligns with the changes made in the pull request.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the unit test `test_clients_add_remove` covers the scenario where a client is removed.
rg --type rust "test_clients_add_remove" crates/ott-balancer/src/balancer.rs

Length of output: 117



Script:

#!/bin/bash
# Extract the contents of the test function `test_clients_add_remove` to verify if it covers the client removal scenario.
rg --type rust --context 10 "async fn test_clients_add_remove" crates/ott-balancer/src/balancer.rs

Length of output: 881



Script:

#!/bin/bash
# Request the continuation of the test function `test_clients_add_remove` to see the test logic for client removal.
rg --type rust --after-context 40 "async fn test_clients_add_remove" crates/ott-balancer/src/balancer.rs

Length of output: 1723



Script:

#!/bin/bash
# Request the continuation of the test function `test_clients_add_remove` beyond the current output to see the test logic for client removal.
rg --type rust --after-context 60 "async fn test_clients_add_remove" crates/ott-balancer/src/balancer.rs

Length of output: 2302

* 708-781: The unit test `test_clients_add_remove` appears to cover the scenario of adding and removing a client. It's important to ensure that the test adequately tests the functionality and that it passes successfully.

async fn test_clients_add_remove() {
// a bunch of setup
let room_name = RoomName::from("test");
let mut ctx = BalancerContext::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

BalancerContext is simply a struct that describes the state of the balancer, including quantity of rooms per monolith, how many instances of a monolith per region, etc. correct?

Copy link
Owner Author

Choose a reason for hiding this comment

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

yeah

},
proxy_port: 3000,
},
monolith_outbound_tx,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these defined in a different scope to that of the other values? Is it because the new() constructor takes them as arguments?

Copy link
Owner Author

Choose a reason for hiding this comment

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

The channels need to be defined at the function level context so they stay alive for the entire unit test. Otherwise the channels get disposed immediately and the test will fail.

@dyc3 dyc3 merged commit e4278c9 into master Jan 12, 2024
18 checks passed
@dyc3 dyc3 deleted the fix-client-leak branch January 12, 2024 02:31
cjrkoa pushed a commit to cjrkoa/opentogethertube that referenced this pull request Jan 26, 2024
…onnect (dyc3#1212)

* balancer: fix clients not being removed from balancer context on disconnect
possibly related to dyc3#1207?

* add a unit test
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.

2 participants