From 118a9e1a516028b75f2dbf7c50ed8a4f28fe20f5 Mon Sep 17 00:00:00 2001 From: Nick Steel Date: Wed, 25 Sep 2024 20:34:59 +0100 Subject: [PATCH] core: AP connection attempts have 3 sec timeout. (#1350) --- CHANGELOG.md | 1 + core/src/connection/mod.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c70c72cb..2fb79f055 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ https://github.com/librespot-org/librespot - [core] Support `Session` authentication with a Spotify access token - [core] `Credentials.username` is now an `Option` (breaking) - [core] `Session::connect` tries multiple access points, retrying each one. +- [core] Each access point connection now timesout after 3 seconds. - [main] `autoplay {on|off}` now acts as an override. If unspecified, `librespot` now follows the setting in the Connect client that controls it. (breaking) - [metadata] Most metadata is now retrieved with the `spclient` (breaking) diff --git a/core/src/connection/mod.rs b/core/src/connection/mod.rs index 8fb596f95..c46e5ad8f 100644 --- a/core/src/connection/mod.rs +++ b/core/src/connection/mod.rs @@ -3,7 +3,7 @@ mod handshake; pub use self::{codec::ApCodec, handshake::handshake}; -use std::io; +use std::{io, time::Duration}; use futures_util::{SinkExt, StreamExt}; use num_traits::FromPrimitive; @@ -63,7 +63,8 @@ impl From for AuthenticationError { } pub async fn connect(host: &str, port: u16, proxy: Option<&Url>) -> io::Result { - let socket = crate::socket::connect(host, port, proxy).await?; + const TIMEOUT: Duration = Duration::from_secs(3); + let socket = tokio::time::timeout(TIMEOUT, crate::socket::connect(host, port, proxy)).await??; handshake(socket).await }