@@ -178,18 +178,18 @@ impl DockerData {
178
178
let all_ids = self . app_data . lock ( ) . get_all_id_state ( ) ;
179
179
for ( state, id) in all_ids {
180
180
let spawn_id = SpawnId :: Stats ( ( id, self . binate ) ) ;
181
- self . spawns
182
- . lock ( )
183
- . entry ( spawn_id. clone ( ) )
184
- . or_insert_with ( || {
185
- tokio:: spawn ( Self :: update_container_stat (
186
- Arc :: clone ( & self . app_data ) ,
187
- Arc :: clone ( & self . docker ) ,
188
- state,
189
- spawn_id,
190
- Arc :: clone ( & self . spawns ) ,
191
- ) )
192
- } ) ;
181
+
182
+ if let std :: collections :: hash_map :: Entry :: Vacant ( spawns ) =
183
+ self . spawns . lock ( ) . entry ( spawn_id. clone ( ) )
184
+ {
185
+ spawns . insert ( tokio:: spawn ( Self :: update_container_stat (
186
+ Arc :: clone ( & self . app_data ) ,
187
+ Arc :: clone ( & self . docker ) ,
188
+ state,
189
+ spawn_id,
190
+ Arc :: clone ( & self . spawns ) ,
191
+ ) ) ) ;
192
+ }
193
193
}
194
194
self . binate = self . binate . toggle ( ) ;
195
195
}
@@ -305,19 +305,20 @@ impl DockerData {
305
305
self . update_all_containers ( ) . await ;
306
306
if let Some ( container) = self . app_data . lock ( ) . get_selected_container ( ) {
307
307
let last_updated = container. last_updated ;
308
- self . spawns
309
- . lock ( )
310
- . entry ( SpawnId :: Log ( container. id . clone ( ) ) )
311
- . or_insert_with ( || {
312
- tokio:: spawn ( Self :: update_log (
313
- Arc :: clone ( & self . app_data ) ,
314
- Arc :: clone ( & self . docker ) ,
315
- container. id . clone ( ) ,
316
- last_updated,
317
- Arc :: clone ( & self . spawns ) ,
318
- self . args . std_err ,
319
- ) )
320
- } ) ;
308
+ let spawn_id = SpawnId :: Log ( container. id . clone ( ) ) ;
309
+ // Only spawn if not already sapwned with a given id/binate pair
310
+ if let std:: collections:: hash_map:: Entry :: Vacant ( spawns) =
311
+ self . spawns . lock ( ) . entry ( spawn_id)
312
+ {
313
+ spawns. insert ( tokio:: spawn ( Self :: update_log (
314
+ Arc :: clone ( & self . app_data ) ,
315
+ Arc :: clone ( & self . docker ) ,
316
+ container. id . clone ( ) ,
317
+ last_updated,
318
+ Arc :: clone ( & self . spawns ) ,
319
+ self . args . std_err ,
320
+ ) ) ) ;
321
+ }
321
322
} ;
322
323
self . update_all_container_stats ( ) ;
323
324
self . app_data . lock ( ) . sort_containers ( ) ;
0 commit comments