Skip to content

Commit

Permalink
adjust client reconnect: discarding incoming user messages, return if…
Browse files Browse the repository at this point in the history
… the client itself is dead instead of hanging
  • Loading branch information
UkoeHB committed Sep 26, 2023
1 parent 95f1155 commit 63ec851
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,22 @@ impl<E: ClientExt> ClientActor<E> {
};
tracing::info!("reconnecting in {}s", reconnect_interval.as_secs());
for i in 1.. {
tokio::time::sleep(reconnect_interval).await;
// discard messages until either the reconnect interval passes or the socket receiver disconnects
let sleep = tokio::time::sleep(reconnect_interval);
tokio::pin!(sleep);
loop {
tokio::select! {
_ = &mut sleep => break,
Some(_) = self.to_socket_receiver.recv() => {
tracing::warn!("client is reconnecting, discarding message from user");
continue
},
else => {
tracing::warn!("client is dead, aborting reconnect");
return

Check failure on line 403 in src/client.rs

View workflow job for this annotation

GitHub Actions / Check

`return;` in a function whose return type is not `()`

Check failure on line 403 in src/client.rs

View workflow job for this annotation

GitHub Actions / Lints

`return;` in a function whose return type is not `()`

Check failure on line 403 in src/client.rs

View workflow job for this annotation

GitHub Actions / Test Suite

`return;` in a function whose return type is not `()`
},
}
}
tracing::info!("reconnecting attempt no: {}...", i);
let connect_http_request = self.config.connect_http_request();
let result = tokio_tungstenite::connect_async(connect_http_request).await;
Expand Down

0 comments on commit 63ec851

Please sign in to comment.