@@ -484,7 +484,11 @@ impl Routes {
484484 expiry
485485 } ;
486486 tokio:: select! {
487- ( ) = tokio:: time:: sleep_until( expiry) => return ,
487+ ( ) = tokio:: time:: sleep_until( expiry) => {
488+ // A renewal and the old timer can both become ready before
489+ // this task is polled. Check the current lease before closing.
490+ if !self . valid( route, token) { return ; }
491+ } ,
488492 result = receiver. changed( ) => if result. is_err( ) { return ; } ,
489493 }
490494 }
@@ -1119,6 +1123,44 @@ mod tests {
11191123 assert ! ( source( Duration :: from_secs( 15 ) ) . routes. is_empty( ) ) ;
11201124 }
11211125
1126+ #[ tokio:: test( start_paused = true ) ]
1127+ async fn queued_authority_renewal_preserves_stream_until_current_expiry ( ) {
1128+ // Exercise selection with both the old timer and renewal notification
1129+ // ready, without letting the stream task observe the renewal early.
1130+ for _ in 0 ..64 {
1131+ let routes = Routes {
1132+ requires_authority : true ,
1133+ ..Default :: default ( )
1134+ } ;
1135+ routes. serving . store ( true , Ordering :: Release ) ;
1136+ let route = SandboxServiceRoute {
1137+ endpoint_id : "endpoint" . into ( ) ,
1138+ name : "web" . into ( ) ,
1139+ target_port : 8080 ,
1140+ authorization_mode : 1 ,
1141+ resource_version : 1 ,
1142+ application_hostname : String :: new ( ) ,
1143+ } ;
1144+ routes. install ( & installed ( vec ! [ route. clone( ) ] ) ) ;
1145+ let source = routes. installation_source ( ) ;
1146+ source ( Duration :: from_secs ( 15 ) ) ;
1147+ let ( _, token) = routes
1148+ . resolve ( HOST , "default--sandbox-a" , "svc.openshell.internal" )
1149+ . unwrap ( ) ;
1150+ let revoked = routes. revoked ( & route, token) ;
1151+ tokio:: pin!( revoked) ;
1152+ assert ! ( futures:: poll!( & mut revoked) . is_pending( ) ) ;
1153+ tokio:: time:: advance ( Duration :: from_secs ( 10 ) ) . await ;
1154+ source ( Duration :: from_secs ( 15 ) ) ;
1155+ tokio:: time:: advance ( Duration :: from_secs ( 6 ) ) . await ;
1156+ assert ! ( routes. valid( & route, token) ) ;
1157+ assert ! ( futures:: poll!( & mut revoked) . is_pending( ) ) ;
1158+ tokio:: time:: advance ( Duration :: from_secs ( 10 ) ) . await ;
1159+ assert ! ( !routes. valid( & route, token) ) ;
1160+ assert ! ( futures:: poll!( & mut revoked) . is_ready( ) ) ;
1161+ }
1162+ }
1163+
11221164 #[ tokio:: test( start_paused = true ) ]
11231165 async fn shared_authority_expires_despite_config_renewal_and_fences_old_streams ( ) {
11241166 let routes = Routes {
0 commit comments