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

refactor: add auto reconnect to curp client #972

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

bsbds
Copy link
Collaborator

@bsbds bsbds commented Aug 30, 2024

This PR includes two major changes:

  • Implements an auto reconnect layer.
  • Lazily build connections for client.

Please briefly answer these questions:

  • what problem are you trying to solve? (or if there's no problem, what's the motivation for this change?)

  • what changes does this pull request make?

  • are there any non-obvious implications of these changes? (does it break compatibility with previous versions, etc)

* Removes unecessary async
* Panics when url is ill-formed instead of returning an error

Signed-off-by: bsbds <[email protected]>
Signed-off-by: bsbds <[email protected]>
Signed-off-by: bsbds <[email protected]>
Signed-off-by: bsbds <[email protected]>
The lock test uses time to sync two tokio tasks, which may cause problem
becuase client propose may takes indefinite time. This commit refactor it
to use a `Event` for sync instead.

Signed-off-by: bsbds <[email protected]>
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 26 lines in your changes missing coverage. Please review.

Project coverage is 75.20%. Comparing base (e35b35a) to head (2e7d80f).
Report is 301 commits behind head on master.

Files with missing lines Patch % Lines
crates/curp/src/rpc/reconnect.rs 86.76% 4 Missing and 5 partials ⚠️
crates/curp/src/client/unary.rs 44.44% 3 Missing and 2 partials ⚠️
crates/curp/src/client/retry.rs 0.00% 0 Missing and 4 partials ⚠️
crates/curp/src/client/state.rs 84.61% 3 Missing and 1 partial ⚠️
crates/curp/src/rpc/connect.rs 95.45% 0 Missing and 2 partials ⚠️
crates/xline-client/src/lib.rs 0.00% 0 Missing and 1 partial ⚠️
crates/xline/src/server/xline_server.rs 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #972      +/-   ##
==========================================
- Coverage   75.55%   75.20%   -0.35%     
==========================================
  Files         180      190      +10     
  Lines       26938    28426    +1488     
  Branches    26938    28426    +1488     
==========================================
+ Hits        20353    21379    +1026     
- Misses       5366     5747     +381     
- Partials     1219     1300      +81     

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

@bsbds bsbds marked this pull request as ready for review August 30, 2024 02:48
@mergify mergify bot requested a review from a team August 30, 2024 02:48
Copy link
Collaborator

@Phoenix500526 Phoenix500526 left a comment

Choose a reason for hiding this comment

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

What is the principle behind changing an async method to a sync one, or vice versa? Please squash these commits into one

/// Connect to a server
async fn connect_to<Client: FromTonicChannel>(
/// Creates a new connection
fn connect_to<Client: FromTonicChannel>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you change this method from async to sync?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The change_tx.send is in a synchronous context, where a try_send should never blocks. Therefore it is unecessary to use async here.

.await
.into_iter()
.collect::<Result<Vec<_>, _>>()
/// Creates a new connection with auto reconnect
Copy link
Collaborator

Choose a reason for hiding this comment

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

In what situation we need such a reconnect mechanism?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please refer to: hyperium/tonic#1254.

@mergify mergify bot requested a review from a team September 9, 2024 01:08
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