@@ -15,17 +15,15 @@ use crate::{
1515 service:: { Request , Response , Service } ,
1616} ;
1717use core:: panic;
18+ use std:: time:: { Duration , Instant } ;
1819use std:: {
1920 collections:: BTreeMap ,
2021 error:: Error ,
2122 fmt:: { Debug , Display } ,
2223 ops:: Sub ,
2324 sync:: { Arc , Mutex , RwLock , Weak } ,
2425} ;
25- use tokio:: {
26- sync:: { mpsc, oneshot, watch, Notify } ,
27- time:: { Duration , Instant } ,
28- } ;
26+ use tokio:: sync:: { mpsc, oneshot, watch, Notify } ;
2927use tonic:: async_trait;
3028
3129type SharedService = Arc < dyn Service > ;
@@ -358,7 +356,7 @@ impl InternalSubchannel {
358356
359357 let connect_task = self . runtime . spawn ( Box :: pin ( async move {
360358 tokio:: select! {
361- _ = tokio :: time :: sleep( min_connect_timeout) => {
359+ _ = runtime . sleep( min_connect_timeout) => {
362360 let _ = state_machine_tx. send( SubchannelStateMachineEvent :: ConnectionTimedOut ) ;
363361 }
364362 result = transport. connect( address. to_string( ) . clone( ) , runtime, & transport_opts) => {
@@ -400,7 +398,7 @@ impl InternalSubchannel {
400398 // terminated? But what can we do with that error other than logging
401399 // it, which the transport can do as well?
402400 if let Err ( e) = closed_rx. await {
403- eprintln ! ( "Transport closed with error: {}" , e . to_string ( ) )
401+ eprintln ! ( "Transport closed with error: {e }" , )
404402 } ;
405403 let _ = state_machine_tx. send ( SubchannelStateMachineEvent :: ConnectionTerminated ) ;
406404 } ) ) ;
@@ -430,8 +428,11 @@ impl InternalSubchannel {
430428
431429 let backoff_interval = self . backoff . backoff_until ( ) ;
432430 let state_machine_tx = self . state_machine_event_sender . clone ( ) ;
431+ let runtime = self . runtime . clone ( ) ;
433432 let backoff_task = self . runtime . spawn ( Box :: pin ( async move {
434- tokio:: time:: sleep_until ( backoff_interval) . await ;
433+ runtime
434+ . sleep ( backoff_interval. saturating_duration_since ( Instant :: now ( ) ) )
435+ . await ;
435436 let _ = state_machine_tx. send ( SubchannelStateMachineEvent :: BackoffExpired ) ;
436437 } ) ) ;
437438 let mut inner = self . inner . lock ( ) . unwrap ( ) ;
0 commit comments