Skip to content

Commit

Permalink
core: audio key response timeout after 1.5s
Browse files Browse the repository at this point in the history
Previously this could wait here indefinitely.
  • Loading branch information
kingosticks committed Oct 6, 2024
1 parent 118a9e1 commit 6831433
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/src/audio_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, io::Write};
use std::{collections::HashMap, io::Write, time::Duration};

use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use bytes::Bytes;
Expand All @@ -20,6 +20,8 @@ pub enum AudioKeyError {
Packet(u8),
#[error("sequence {0} not pending")]
Sequence(u32),
#[error("audio key response timeout")]
Timeout,
}

impl From<AudioKeyError> for Error {
Expand All @@ -29,6 +31,7 @@ impl From<AudioKeyError> for Error {
AudioKeyError::Channel => Error::aborted(err),
AudioKeyError::Sequence(_) => Error::aborted(err),
AudioKeyError::Packet(_) => Error::unimplemented(err),
AudioKeyError::Timeout => Error::aborted(err),
}
}
}
Expand Down Expand Up @@ -89,7 +92,14 @@ impl AudioKeyManager {
});

self.send_key_request(seq, track, file)?;
rx.await?
const KEY_RESPONSE_TIMEOUT: Duration = Duration::from_millis(1500);
match tokio::time::timeout(KEY_RESPONSE_TIMEOUT, rx).await {
Err(_) => {
error!("Audio key response timeout");
Err(AudioKeyError::Timeout.into())
}
Ok(k) => k?,
}
}

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

0 comments on commit 6831433

Please sign in to comment.