Skip to content

Commit 118a9e1

Browse files
authored
core: AP connection attempts have 3 sec timeout. (#1350)
1 parent e02e4ae commit 118a9e1

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ https://github.com/librespot-org/librespot
5858
- [core] Support `Session` authentication with a Spotify access token
5959
- [core] `Credentials.username` is now an `Option` (breaking)
6060
- [core] `Session::connect` tries multiple access points, retrying each one.
61+
- [core] Each access point connection now timesout after 3 seconds.
6162
- [main] `autoplay {on|off}` now acts as an override. If unspecified, `librespot`
6263
now follows the setting in the Connect client that controls it. (breaking)
6364
- [metadata] Most metadata is now retrieved with the `spclient` (breaking)

core/src/connection/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod handshake;
33

44
pub use self::{codec::ApCodec, handshake::handshake};
55

6-
use std::io;
6+
use std::{io, time::Duration};
77

88
use futures_util::{SinkExt, StreamExt};
99
use num_traits::FromPrimitive;
@@ -63,7 +63,8 @@ impl From<APLoginFailed> for AuthenticationError {
6363
}
6464

6565
pub async fn connect(host: &str, port: u16, proxy: Option<&Url>) -> io::Result<Transport> {
66-
let socket = crate::socket::connect(host, port, proxy).await?;
66+
const TIMEOUT: Duration = Duration::from_secs(3);
67+
let socket = tokio::time::timeout(TIMEOUT, crate::socket::connect(host, port, proxy)).await??;
6768

6869
handshake(socket).await
6970
}

0 commit comments

Comments
 (0)