-
Notifications
You must be signed in to change notification settings - Fork 80
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
Async reconnections #400
Async reconnections #400
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR! Really appreciate you working on that :) I left a few comments, generally this looks good.
afb2e91
to
fab1dab
Compare
@1c3t3a I've incorporated all the suggestions. While adding the test I realized I hadn't made I made quite a few commits while trying to fix that, but I've squashed everything into just one so it's a clean update. Please take another look and let me know if I've missed something. Thanks! |
There's one more problem that I really think should be solved with reconnects. The async client today has no way to update the This might be beyond the scope of this PR, though. Maybe I should open another issue for it? Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
I hadn't made Client::socket an Arc
Yes, that's one necessary step!
auth field
Maybe better to do this separately! :)
167edd4
to
3dcf5ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @1c3t3a asked me to take a look at this. These are my first thoughts.
Lets run the CI! |
I fixed the tokio CI issue in main, feel free to rebase :) Then we see the "real" tests of this PR. |
The builder can now be configured with the following properties to control automatic reconnections on network errors or server disconnects: - reconnect - reconnect_on_disconnect - reconnect_delay (min and max) - max_reconnect_attempts
The async client can now be configured to automatically reconnect on network errors or server disconnections
The enum replaces the need for multiple `AtomicBool`'s to maintain the disconnection reason. This makes the code easier to read and more ergonomic to maintain the state.
20243af
to
210fe95
Compare
Thanks @1c3t3a. Rebased just now. Let's see how it goes! 😄 |
Well, that was dumb of me. We can't do a I somehow forgot to run the tests after making that change yesterday. Sorry about that! |
@@ -854,7 +847,7 @@ mod test { | |||
.await?; | |||
|
|||
// open packet | |||
let mut socket_stream = socket.as_stream(); | |||
let mut socket_stream = socket.as_stream().await; | |||
let _ = socket_stream.next().await.unwrap()?; | |||
|
|||
println!("Here12"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw this now: Where does that come from? :) (The println
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't me. Apparently you added it 12 months ago: https://github.com/1c3t3a/rust-socketio/pull/296/files#diff-dd5d6ff18628a21723847133d6e54ab531454037b62be81d2c42109d333aeab9R609 😆
I'll remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Is the current failure a flaky test? It's coming from a sync client test, but I'm getting 100% pass locally. |
I never saw a flaky test in this repo.. that is weird. How do you execute the servers locally? Do you use the devcontainer? |
Does the server side test have any state? E.g. you first execute the async test and then it doesn't work anymore? |
No, I fired up the docker container for the websocket server and ran |
Ahh, I see what I was missing now... I wasn't passing |
Tests that rely on the reconnect socket server cannot run in parallel because they ask the server to disconnect and restart as part of the test. This can cause other tests running in parallel to fail in mysterious ways. By using the `serial_test` module and applying it selectively to the affected tests, we can ensure that they are never executed concurrently.
…socketio into feat/async-reconnect
It was because the new test I added in the async client uses the same My solution to this is adding a new dev-dependency on the With this, |
Here's the commit that adds it: e2eea62 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #400 +/- ##
==========================================
+ Coverage 91.97% 92.05% +0.07%
==========================================
Files 36 36
Lines 4872 5007 +135
==========================================
+ Hits 4481 4609 +128
- Misses 391 398 +7 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! This was a big one, thanks a lot @rageshkrishna for implementing this, really appreciated :)
The async client and builder can now attempt to reconnect to the server on connection errors.
Fixes #291