From 4effe38c1df1610cbf6947ea22ca5b81955b8292 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 5 Jul 2022 20:49:32 +0200 Subject: [PATCH] Increase ping and reply timeout While downloading logs for &music, the server would repeatedly time out on ws pings because it took too much time responding to the log commands. This change makes reconnects less likely at the cost of not noticing them as quickly. --- src/euph/conn.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/euph/conn.rs b/src/euph/conn.rs index a175f07..c723211 100644 --- a/src/euph/conn.rs +++ b/src/euph/conn.rs @@ -27,6 +27,10 @@ use super::api::{ pub type WsStream = WebSocketStream>; +/// Timeout used for any kind of reply from the server, including to ws and euph +/// pings. Also used as the time in-between pings. +const TIMEOUT: Duration = Duration::from_secs(30); // TODO Make configurable + #[derive(Debug, thiserror::Error)] pub enum Error { #[error("connection closed")] @@ -182,7 +186,7 @@ impl State { let mut state = Self { ws_tx, last_id: 0, - replies: Replies::new(Duration::from_secs(10)), // TODO Make configurable + replies: Replies::new(TIMEOUT), packet_tx, last_ws_ping: None, last_ws_pong: None, @@ -213,7 +217,7 @@ impl State { async fn send_ping_events(event_tx: &mpsc::UnboundedSender) -> anyhow::Result<()> { loop { event_tx.send(Event::DoPings)?; - time::sleep(Duration::from_secs(10)).await; // TODO Make configurable + time::sleep(TIMEOUT).await; } }