@@ -174,6 +174,7 @@ pub trait MultiTargetHandlers<
174174
175175struct RuntimeInfo < N : NotifyTarget > {
176176 notify_target : N ,
177+ session_id : String ,
177178 targets : HashMap < Arc < Target > , u32 > ,
178179}
179180
@@ -212,7 +213,8 @@ where
212213
213214 fn remove_target (
214215 self : & Arc < Self > ,
215- runtime_id : & str ,
216+ instance_runtime_id : & str ,
217+ session_id : & str ,
216218 target : & Arc < Target > ,
217219 runtimes : MutexGuard < HashMap < String , RuntimeInfo < N > > > ,
218220 ) {
@@ -229,13 +231,19 @@ where
229231 match * status {
230232 KnownTargetStatus :: Removing ( ref future) => {
231233 let future = future. clone ( ) ;
232- let runtime_id = runtime_id. to_string ( ) ;
234+ let instance_runtime_id = instance_runtime_id. to_string ( ) ;
235+ let session_id = session_id. to_string ( ) ;
233236 let this = self . clone ( ) ;
234237 let target = target. clone ( ) ;
235238 tokio:: spawn ( async move {
236239 future. await ;
237240 let runtimes = this. runtimes . lock_or_panic ( ) ;
238- this. remove_target ( runtime_id. as_str ( ) , & target, runtimes) ;
241+ this. remove_target (
242+ instance_runtime_id. as_str ( ) ,
243+ session_id. as_str ( ) ,
244+ & target,
245+ runtimes,
246+ ) ;
239247 } ) ;
240248 return ;
241249 }
@@ -246,7 +254,7 @@ where
246254 }
247255 }
248256 1 => {
249- known_service. runtimes . remove ( runtime_id ) ;
257+ known_service. runtimes . remove ( instance_runtime_id ) ;
250258 let mut status = known_service. status . lock_or_panic ( ) ;
251259 * status = match * status {
252260 KnownTargetStatus :: Pending => KnownTargetStatus :: Alive , /* not really */
@@ -265,7 +273,9 @@ where
265273 0
266274 }
267275 _ => {
268- if let Some ( product_data) = known_service. runtimes . remove ( runtime_id) {
276+ if let Some ( product_data) =
277+ known_service. runtimes . remove ( instance_runtime_id)
278+ {
269279 let mut update_product_data = false ;
270280 for product in product_data. products {
271281 update_product_data =
@@ -285,15 +295,15 @@ where
285295 return ;
286296 }
287297 if known_service. fetcher . runtime_id . lock_or_panic ( ) . as_str ( )
288- == runtime_id
298+ == session_id
289299 {
290300 ' changed_rt_id: {
291- for ( id , runtime) in runtimes. iter ( ) {
301+ for ( _ , runtime) in runtimes. iter ( ) {
292302 if runtime. targets . len ( ) == 1
293303 && runtime. targets . contains_key ( target)
294304 {
295305 * known_service. fetcher . runtime_id . lock_or_panic ( ) =
296- Arc :: new ( id . to_string ( ) ) ;
306+ Arc :: new ( runtime . session_id . clone ( ) ) ;
297307 break ' changed_rt_id;
298308 }
299309 }
@@ -317,6 +327,7 @@ where
317327 self : & Arc < Self > ,
318328 synthetic_id : bool ,
319329 runtime_id : & str ,
330+ session_id : & str ,
320331 target : Arc < Target > ,
321332 product_capabilities : ProductCapabilities ,
322333 ) {
@@ -351,12 +362,14 @@ where
351362 // Avoid deadlocking between known_target.status and self.services
352363 self . pending_async_insertions . fetch_add ( 1 , Ordering :: AcqRel ) ;
353364 let runtime_id = runtime_id. to_string ( ) ;
365+ let session_id = session_id. to_string ( ) ;
354366 let this = self . clone ( ) ;
355367 tokio:: spawn ( async move {
356368 future. await ;
357369 this. add_target (
358370 synthetic_id,
359371 runtime_id. as_str ( ) ,
372+ session_id. as_str ( ) ,
360373 target,
361374 product_capabilities,
362375 ) ;
@@ -398,7 +411,7 @@ where
398411 . insert ( runtime_id. to_string ( ) , product_capabilities) ;
399412 if !synthetic_id && known_target. synthetic_id {
400413 known_target. synthetic_id = false ;
401- * known_target. fetcher . runtime_id . lock_or_panic ( ) = Arc :: new ( runtime_id . into ( ) ) ;
414+ * known_target. fetcher . runtime_id . lock_or_panic ( ) = Arc :: new ( session_id . into ( ) ) ;
402415 }
403416 }
404417 Entry :: Vacant ( e) => {
@@ -433,7 +446,7 @@ where
433446 if synthetic_id {
434447 Self :: generate_synthetic_id ( )
435448 } else {
436- runtime_id . into ( )
449+ session_id . into ( )
437450 } ,
438451 ConfigProductCapabilities :: new (
439452 product_capabilities. products ,
@@ -448,6 +461,7 @@ where
448461
449462 pub fn add_runtime (
450463 self : & Arc < Self > ,
464+ session_id : String ,
451465 runtime_id : String ,
452466 notify_target : N ,
453467 target : & Arc < Target > ,
@@ -480,6 +494,7 @@ where
480494 self . add_target (
481495 true ,
482496 runtime_entry. key ( ) ,
497+ session_id. as_str ( ) ,
483498 target. clone ( ) ,
484499 product_capabilities,
485500 ) ;
@@ -498,16 +513,28 @@ where
498513 {
499514 let info = RuntimeInfo {
500515 notify_target,
516+ session_id : session_id. clone ( ) ,
501517 targets : HashMap :: from ( [ ( target. clone ( ) , 1 ) ] ) ,
502518 } ;
503- self . add_target ( false , e. key ( ) , target. clone ( ) , product_capabilities) ;
519+ self . add_target (
520+ false ,
521+ e. key ( ) ,
522+ session_id. as_str ( ) ,
523+ target. clone ( ) ,
524+ product_capabilities,
525+ ) ;
504526 e. insert ( info) ;
505527 }
506528 }
507529 }
508530 }
509531
510- pub fn delete_runtime ( self : & Arc < Self > , runtime_id : & str , target : & Arc < Target > ) {
532+ pub fn delete_runtime (
533+ self : & Arc < Self > ,
534+ runtime_id : & str ,
535+ session_id : & str ,
536+ target : & Arc < Target > ,
537+ ) {
511538 trace ! ( "Removing remote config runtime: {target:?} with runtime id {runtime_id}" ) ;
512539 let mut runtimes = self . runtimes . lock_or_panic ( ) ;
513540 let last_removed = {
@@ -531,7 +558,7 @@ where
531558 if last_removed {
532559 runtimes. remove ( runtime_id) ;
533560 }
534- Self :: remove_target ( self , runtime_id, target, runtimes) ;
561+ Self :: remove_target ( self , runtime_id, session_id , target, runtimes) ;
535562 }
536563
537564 /// Sets the apply state on a stored file.
@@ -935,6 +962,7 @@ mod tests {
935962 fetcher. remote_config_interval . store ( 1000 , Ordering :: SeqCst ) ;
936963
937964 fetcher. add_runtime (
965+ RT_ID_1 . to_string ( ) ,
938966 RT_ID_1 . to_string ( ) ,
939967 Notifier {
940968 id : 1 ,
@@ -962,6 +990,7 @@ mod tests {
962990 ) ;
963991
964992 fetcher. add_runtime (
993+ RT_ID_1 . to_string ( ) ,
965994 RT_ID_1 . to_string ( ) ,
966995 Notifier {
967996 id : 1 ,
@@ -974,6 +1003,7 @@ mod tests {
9741003 } ,
9751004 ) ;
9761005 fetcher. add_runtime (
1006+ RT_ID_2 . to_string ( ) ,
9771007 RT_ID_2 . to_string ( ) ,
9781008 Notifier {
9791009 id : 2 ,
@@ -1019,6 +1049,7 @@ mod tests {
10191049 assert_eq ! ( fetcher. services. lock( ) . unwrap( ) . len( ) , 2 ) ; // two fetchers
10201050
10211051 fetcher. add_runtime (
1052+ RT_ID_3 . to_string ( ) ,
10221053 RT_ID_3 . to_string ( ) ,
10231054 Notifier {
10241055 id : 3 ,
@@ -1080,10 +1111,10 @@ mod tests {
10801111 ) ;
10811112 }
10821113
1083- fetcher. delete_runtime ( RT_ID_1 , & OTHER_TARGET ) ;
1084- fetcher. delete_runtime ( RT_ID_1 , & DUMMY_TARGET ) ;
1085- fetcher. delete_runtime ( RT_ID_2 , & DUMMY_TARGET ) ;
1086- fetcher. delete_runtime ( RT_ID_3 , & OTHER_TARGET ) ;
1114+ fetcher. delete_runtime ( RT_ID_1 , RT_ID_1 , & OTHER_TARGET ) ;
1115+ fetcher. delete_runtime ( RT_ID_1 , RT_ID_1 , & DUMMY_TARGET ) ;
1116+ fetcher. delete_runtime ( RT_ID_2 , RT_ID_2 , & DUMMY_TARGET ) ;
1117+ fetcher. delete_runtime ( RT_ID_3 , RT_ID_3 , & OTHER_TARGET ) ;
10871118
10881119 fetcher. shutdown ( ) ;
10891120 storage. expect_expiration ( & DUMMY_TARGET ) ;
0 commit comments