Skip to content

Commit 8b769e0

Browse files
authored
core: audio key response timeout after 1.5s (#1360)
1 parent 0ddb3b4 commit 8b769e0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

core/src/audio_key.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, io::Write};
1+
use std::{collections::HashMap, io::Write, time::Duration};
22

33
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
44
use bytes::Bytes;
@@ -20,6 +20,8 @@ pub enum AudioKeyError {
2020
Packet(u8),
2121
#[error("sequence {0} not pending")]
2222
Sequence(u32),
23+
#[error("audio key response timeout")]
24+
Timeout,
2325
}
2426

2527
impl From<AudioKeyError> for Error {
@@ -29,6 +31,7 @@ impl From<AudioKeyError> for Error {
2931
AudioKeyError::Channel => Error::aborted(err),
3032
AudioKeyError::Sequence(_) => Error::aborted(err),
3133
AudioKeyError::Packet(_) => Error::unimplemented(err),
34+
AudioKeyError::Timeout => Error::aborted(err),
3235
}
3336
}
3437
}
@@ -89,7 +92,14 @@ impl AudioKeyManager {
8992
});
9093

9194
self.send_key_request(seq, track, file)?;
92-
rx.await?
95+
const KEY_RESPONSE_TIMEOUT: Duration = Duration::from_millis(1500);
96+
match tokio::time::timeout(KEY_RESPONSE_TIMEOUT, rx).await {
97+
Err(_) => {
98+
error!("Audio key response timeout");
99+
Err(AudioKeyError::Timeout.into())
100+
}
101+
Ok(k) => k?,
102+
}
93103
}
94104

95105
fn send_key_request(&self, seq: u32, track: SpotifyId, file: FileId) -> Result<(), Error> {

0 commit comments

Comments
 (0)