Skip to content

Commit 640fa99

Browse files
authored
improve reliability of connections (#349)
1 parent bdafaa0 commit 640fa99

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/connect.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,18 @@ async fn ping_pong(
223223
) {
224224
loop {
225225
let (buf, len) = ProtoEvent::Ping.into();
226-
if let Err(e) = conn.send(&buf[..len]).await {
227-
log::warn!("{addr}: send error `{e}`, closing connection");
228-
let _ = conn.close().await;
229-
break;
230-
}
231-
log::trace!("PING >->->->->- {addr}");
232226

233-
tokio::time::sleep(Duration::from_millis(500)).await;
227+
// send 4 pings, at least one must be answered
228+
for _ in 0..4 {
229+
if let Err(e) = conn.send(&buf[..len]).await {
230+
log::warn!("{addr}: send error `{e}`, closing connection");
231+
let _ = conn.close().await;
232+
break;
233+
}
234+
log::trace!("PING >->->->->- {addr}");
235+
236+
tokio::time::sleep(Duration::from_millis(500)).await;
237+
}
234238

235239
if !ping_response.borrow_mut().remove(&addr) {
236240
log::warn!("{addr} did not respond, closing connection");

0 commit comments

Comments
 (0)