@@ -212,8 +212,8 @@ impl RemoteStateActor {
212212 /// discipline is needed to not turn pending for a long time.
213213 async fn run ( mut self , mut inbox : GuardedReceiver < RemoteStateMessage > ) {
214214 trace ! ( "actor started" ) ;
215- let idle_timeout = MaybeFuture :: None ;
216- tokio :: pin!( idle_timeout) ;
215+ let idle_timeout = time :: sleep ( ACTOR_MAX_IDLE_TIMEOUT ) ;
216+ n0_future :: pin!( idle_timeout) ;
217217 loop {
218218 let scheduled_path_open = match self . scheduled_open_path {
219219 Some ( when) => MaybeFuture :: Some ( time:: sleep_until ( when) ) ,
@@ -225,6 +225,11 @@ impl RemoteStateActor {
225225 None => MaybeFuture :: None ,
226226 } ;
227227 n0_future:: pin!( scheduled_hp) ;
228+ if !inbox. is_idle ( ) || !self . connections . is_empty ( ) {
229+ idle_timeout
230+ . as_mut ( )
231+ . reset ( Instant :: now ( ) + ACTOR_MAX_IDLE_TIMEOUT ) ;
232+ }
228233 tokio:: select! {
229234 biased;
230235 msg = inbox. recv( ) => {
@@ -264,20 +269,12 @@ impl RemoteStateActor {
264269 if self . connections. is_empty( ) && inbox. close_if_idle( ) {
265270 trace!( "idle timeout expired and still idle: terminate actor" ) ;
266271 break ;
272+ } else {
273+ // Seems like we weren't really idle, so we reset
274+ idle_timeout. as_mut( ) . reset( Instant :: now( ) + ACTOR_MAX_IDLE_TIMEOUT ) ;
267275 }
268276 }
269277 }
270-
271- let is_idle = self . connections . is_empty ( ) && inbox. is_idle ( ) ;
272- if idle_timeout. is_none ( ) && is_idle {
273- trace ! ( "start idle timeout" ) ;
274- idle_timeout
275- . as_mut ( )
276- . set_future ( time:: sleep ( ACTOR_MAX_IDLE_TIMEOUT ) ) ;
277- } else if idle_timeout. is_some ( ) && !is_idle {
278- trace ! ( "abort idle timeout" ) ;
279- idle_timeout. as_mut ( ) . set_none ( )
280- }
281278 }
282279 trace ! ( "actor terminating" ) ;
283280 }
0 commit comments