@@ -421,6 +421,9 @@ impl ManagedProcess {
421421 #[ cfg( windows) ]
422422 let _console_guard = platform:: console_lock ( ) ;
423423
424+ // Resolve intended spawn user before creating the child so a slow lookup
425+ // cannot block the manager lock while an unwatched process is starting.
426+ self . refresh_intended_user ( ) ;
424427 let handle = platform:: spawn_child_handle ( self ) ?;
425428
426429 self . pid = handle. id ( ) ;
@@ -432,7 +435,6 @@ impl ManagedProcess {
432435 ) ;
433436
434437 self . handle = Some ( handle) ;
435- self . refresh_intended_user ( ) ;
436438 self . transition_to ( ProcessState :: Running ) ;
437439 self . restarts . mark_spawned ( ) ;
438440 Ok ( ( ) )
@@ -970,6 +972,23 @@ pub mod tests {
970972 assert_eq ! ( status. code( ) , Some ( 7 ) ) ;
971973 }
972974
975+ #[ tokio:: test]
976+ async fn test_spawn_refreshes_intended_user_before_running ( ) {
977+ let ( cmd, args) = test_helpers:: true_cmd ( ) ;
978+ let mut proc = ManagedProcess :: new_config (
979+ "spawn-user-refresh" . into ( ) ,
980+ test_helpers:: test_uuid ( ) ,
981+ test_helpers:: make_config ( cmd, args) ,
982+ ) ;
983+ let expected = spawn_user_for ( proc. name ( ) , proc. profile ( ) ) ;
984+ proc. spawn ( ) . unwrap ( ) ;
985+ assert_eq ! ( proc. user( ) , expected) ;
986+ assert ! ( proc. is_running( ) ) ;
987+ let _ = proc. wait ( ) . await ;
988+ }
989+
990+ // -- signal tests (Unix-only: test the raw send_signal API) --
991+
973992 #[ cfg( unix) ]
974993 #[ tokio:: test]
975994 async fn test_send_signal_sigterm ( ) {
0 commit comments