Skip to content

Commit

Permalink
core: AP connection attempts have 3 sec timeout. (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingosticks committed Sep 25, 2024
1 parent e02e4ae commit 118a9e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions core/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,7 +63,8 @@ impl From<APLoginFailed> for AuthenticationError {
}

pub async fn connect(host: &str, port: u16, proxy: Option<&Url>) -> io::Result<Transport> {
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
}
Expand Down

0 comments on commit 118a9e1

Please sign in to comment.