1- use std:: { collections:: HashMap , io:: Write } ;
1+ use std:: { collections:: HashMap , io:: Write , time :: Duration } ;
22
33use byteorder:: { BigEndian , ByteOrder , WriteBytesExt } ;
44use 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
2527impl 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