From e0870a40c439616f4d7bbc69a6491f09a86d929b Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:12:04 +0200 Subject: [PATCH] increase keepalive timeouts we don't really know what the server expects and how quickly it usually reacts, so add some safety margin to avoid timing out too early --- core/src/session.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/src/session.rs b/core/src/session.rs index 23afbed45..ab988f890 100644 --- a/core/src/session.rs +++ b/core/src/session.rs @@ -518,10 +518,10 @@ enum KeepAliveState { ExpectingPongAck, } -const INITIAL_PING_TIMEOUT: TokioDuration = TokioDuration::from_secs(5); -const PING_TIMEOUT: TokioDuration = TokioDuration::from_secs(65); +const INITIAL_PING_TIMEOUT: TokioDuration = TokioDuration::from_secs(20); +const PING_TIMEOUT: TokioDuration = TokioDuration::from_secs(80); // 60s expected + 20s buffer const PONG_DELAY: TokioDuration = TokioDuration::from_secs(60); -const PONG_ACK_TIMEOUT: TokioDuration = TokioDuration::from_secs(5); +const PONG_ACK_TIMEOUT: TokioDuration = TokioDuration::from_secs(20); impl KeepAliveState { fn debug(&self, sleep: &Sleep) { @@ -729,7 +729,7 @@ where } } - // Handle the keee-alive sequence, returning an error when we haven't received a + // Handle the keep-alive sequence, returning an error when we haven't received a // Ping/PongAck for too long. // // The expected keepalive sequence is @@ -741,10 +741,11 @@ where // - repeat // // This means that we silently lost connection to Spotify servers if - // - we don't receive a Ping 60s after the last PongAck, or + // - we don't receive Ping immediately after connecting, + // - we don't receive a Ping 60s after the last PongAck or // - we don't receive a PongAck immediately after our Pong. // - // Currently, we add a safety margin of 5s to these expected deadlines. + // Currently, we add a safety margin of 20s to these expected deadlines. let mut this = self.as_mut().project(); if let Poll::Ready(()) = this.timeout.as_mut().poll(cx) { match this.keep_alive_state {