@@ -348,7 +348,6 @@ pub struct RequestHandle<R: ServiceRole> {
348348 pub peer : Peer < R > ,
349349 pub id : RequestId ,
350350 pub progress_token : ProgressToken ,
351- progress_timeout_watchers : ProgressTimeoutWatchers ,
352351 progress_reset_rx : Option < mpsc:: Receiver < ( ) > > ,
353352}
354353
@@ -416,8 +415,10 @@ impl<R: ServiceRole> RequestHandle<R> {
416415 max_total_timeout : Option < Duration > ,
417416 reset_timeout_on_progress : bool ,
418417 ) -> Result < R :: PeerResp , ServiceError > {
419- let mut idle_sleep = timeout. map ( tokio:: time:: sleep) . map ( Box :: pin) ;
420- let mut max_total_sleep = max_total_timeout. map ( tokio:: time:: sleep) . map ( Box :: pin) ;
418+ let mut idle_sleep =
419+ timeout. map ( |timeout| ( timeout, Box :: pin ( tokio:: time:: sleep ( timeout) ) ) ) ;
420+ let mut max_total_sleep =
421+ max_total_timeout. map ( |timeout| ( timeout, Box :: pin ( tokio:: time:: sleep ( timeout) ) ) ) ;
421422
422423 loop {
423424 tokio:: select! {
@@ -427,32 +428,34 @@ impl<R: ServiceRole> RequestHandle<R> {
427428 return response. map_err( |_e| ServiceError :: TransportClosed ) ?;
428429 }
429430 _ = async {
430- if let Some ( sleep) = idle_sleep. as_mut( ) {
431+ if let Some ( ( _ , sleep) ) = idle_sleep. as_mut( ) {
431432 sleep. as_mut( ) . await ;
432433 }
433434 } , if idle_sleep. is_some( ) => {
434- let timeout = timeout. expect( "idle timeout exists when idle sleep exists" ) ;
435- self . send_timeout_cancel_notification( Self :: REQUEST_TIMEOUT_REASON ) . await ;
436- return Err ( ServiceError :: Timeout { timeout } ) ;
435+ if let Some ( ( timeout, _) ) = idle_sleep. as_ref( ) {
436+ self . send_timeout_cancel_notification( Self :: REQUEST_TIMEOUT_REASON ) . await ;
437+ return Err ( ServiceError :: Timeout { timeout: * timeout } ) ;
438+ }
437439 }
438440 _ = async {
439- if let Some ( sleep) = max_total_sleep. as_mut( ) {
441+ if let Some ( ( _ , sleep) ) = max_total_sleep. as_mut( ) {
440442 sleep. as_mut( ) . await ;
441443 }
442444 } , if max_total_sleep. is_some( ) => {
443- let timeout = max_total_timeout. expect( "max total timeout exists when max total sleep exists" ) ;
444- self . send_timeout_cancel_notification( Self :: REQUEST_MAX_TOTAL_TIMEOUT_REASON ) . await ;
445- return Err ( ServiceError :: Timeout { timeout } ) ;
445+ if let Some ( ( timeout, _) ) = max_total_sleep. as_ref( ) {
446+ self . send_timeout_cancel_notification( Self :: REQUEST_MAX_TOTAL_TIMEOUT_REASON ) . await ;
447+ return Err ( ServiceError :: Timeout { timeout: * timeout } ) ;
448+ }
446449 }
447450 progress = async {
448451 match self . progress_reset_rx. as_mut( ) {
449452 Some ( rx) => rx. recv( ) . await ,
450453 None => None ,
451454 }
452- } , if reset_timeout_on_progress && timeout . is_some( ) && self . progress_reset_rx. is_some( ) => {
455+ } , if reset_timeout_on_progress && idle_sleep . is_some( ) && self . progress_reset_rx. is_some( ) => {
453456 if progress. is_some( ) {
454- if let ( Some ( timeout) , Some ( sleep) ) = ( timeout , idle_sleep. as_mut( ) ) {
455- sleep. as_mut( ) . reset( tokio:: time:: Instant :: now( ) + timeout) ;
457+ if let Some ( ( timeout, sleep) ) = idle_sleep. as_mut( ) {
458+ sleep. as_mut( ) . reset( tokio:: time:: Instant :: now( ) + * timeout) ;
456459 }
457460 }
458461 }
@@ -463,7 +466,7 @@ impl<R: ServiceRole> RequestHandle<R> {
463466 /// Cancel this request
464467 pub async fn cancel ( self , reason : Option < String > ) -> Result < ( ) , ServiceError > {
465468 Self :: cleanup_progress_timeout_watcher (
466- & self . progress_timeout_watchers ,
469+ & self . peer . progress_timeout_watchers ,
467470 & self . progress_token ,
468471 self . progress_reset_rx . is_some ( ) ,
469472 )
@@ -617,12 +620,12 @@ impl<R: ServiceRole> Peer<R> {
617620 ) -> Result < RequestHandle < R > , ServiceError > {
618621 let id = self . request_id_provider . next_request_id ( ) ;
619622 let progress_token = self . progress_token_provider . next_progress_token ( ) ;
620- request
621- . get_meta_mut ( )
622- . set_progress_token ( progress_token. clone ( ) ) ;
623623 if let Some ( meta) = options. meta . clone ( ) {
624624 request. get_meta_mut ( ) . extend ( meta) ;
625625 }
626+ request
627+ . get_meta_mut ( )
628+ . set_progress_token ( progress_token. clone ( ) ) ;
626629 let ( responder, receiver) = tokio:: sync:: oneshot:: channel ( ) ;
627630 let progress_reset_rx = if options. reset_timeout_on_progress && options. timeout . is_some ( ) {
628631 let ( sender, receiver) = mpsc:: channel ( 1 ) ;
@@ -658,7 +661,6 @@ impl<R: ServiceRole> Peer<R> {
658661 progress_token,
659662 options,
660663 peer : self . clone ( ) ,
661- progress_timeout_watchers : self . progress_timeout_watchers . clone ( ) ,
662664 progress_reset_rx,
663665 } )
664666 }
0 commit comments