@@ -115,17 +115,19 @@ fn run_service() -> Result<(), DaemonError> {
115115
116116 let service_location_manager = Arc :: new ( RwLock :: new ( service_location_manager) ) ;
117117
118- // Spawn network change monitoring task first so NotifyAddrChange is registered as early
119- // as possible, minimising the window in which a network event could be missed before
120- // the watcher is listening. The retry task below is the backstop for any event that
121- // still slips through that window.
118+ // Spawn network change monitoring on a dedicated OS thread so the blocking
119+ // NotifyAddrChange syscall does not stall Tokio's async worker threads.
120+ // Register it first so no network event can be missed before the watcher is listening;
121+ // the retry loop below is the backstop for any event that slips through the startup window.
122122 let service_location_manager_clone = service_location_manager. clone ( ) ;
123- runtime. spawn ( async move {
124- let manager = service_location_manager_clone;
125- info ! ( "Starting network change monitoring" ) ;
126- watch_for_network_change ( manager. clone ( ) ) . await ;
127- error ! ( "Network change monitoring ended unexpectedly." ) ;
128- } ) ;
123+ std:: thread:: Builder :: new ( )
124+ . name ( "network-change-monitor" . to_string ( ) )
125+ . spawn ( move || {
126+ info ! ( "Starting network change monitoring" ) ;
127+ watch_for_network_change ( service_location_manager_clone) ;
128+ error ! ( "Network change monitoring ended unexpectedly." ) ;
129+ } )
130+ . expect ( "Failed to spawn network change monitor thread" ) ;
129131
130132 // Spawn service location auto-connect task with retries.
131133 // Each attempt skips locations that are already connected, so it is safe to call
@@ -174,32 +176,34 @@ fn run_service() -> Result<(), DaemonError> {
174176 info ! ( "Service location auto-connect task finished" ) ;
175177 } ) ;
176178
177- // Spawn login/logoff monitoring task, runs concurrently with the tasks above.
179+ // Spawn login/logoff monitoring on a dedicated OS thread so the blocking
180+ // WTSWaitSystemEvent syscall does not stall Tokio's async worker threads.
178181 let service_location_manager_clone = service_location_manager. clone ( ) ;
179- runtime. spawn ( async move {
180- let manager = service_location_manager_clone;
181-
182- info ! ( "Starting login/logoff event monitoring" ) ;
183- loop {
184- match watch_for_login_logoff ( manager. clone ( ) ) . await {
185- Ok ( ( ) ) => {
186- warn ! (
187- "Login/logoff event monitoring ended unexpectedly. Restarting in \
188- {LOGIN_LOGOFF_MONITORING_RESTART_DELAY_SECS:?}..."
189- ) ;
190- sleep ( LOGIN_LOGOFF_MONITORING_RESTART_DELAY_SECS ) . await ;
191- }
192- Err ( e) => {
193- error ! (
194- "Error in login/logoff event monitoring: {e}. Restarting in \
195- {LOGIN_LOGOFF_MONITORING_RESTART_DELAY_SECS:?}...",
196- ) ;
197- sleep ( LOGIN_LOGOFF_MONITORING_RESTART_DELAY_SECS ) . await ;
198- info ! ( "Restarting login/logoff event monitoring" ) ;
182+ std:: thread:: Builder :: new ( )
183+ . name ( "login-logoff-monitor" . to_string ( ) )
184+ . spawn ( move || {
185+ info ! ( "Starting login/logoff event monitoring" ) ;
186+ loop {
187+ match watch_for_login_logoff ( service_location_manager_clone. clone ( ) ) {
188+ Ok ( ( ) ) => {
189+ warn ! (
190+ "Login/logoff event monitoring ended unexpectedly. Restarting in \
191+ {LOGIN_LOGOFF_MONITORING_RESTART_DELAY_SECS:?}..."
192+ ) ;
193+ std:: thread:: sleep ( LOGIN_LOGOFF_MONITORING_RESTART_DELAY_SECS ) ;
194+ }
195+ Err ( e) => {
196+ error ! (
197+ "Error in login/logoff event monitoring: {e}. Restarting in \
198+ {LOGIN_LOGOFF_MONITORING_RESTART_DELAY_SECS:?}...",
199+ ) ;
200+ std:: thread:: sleep ( LOGIN_LOGOFF_MONITORING_RESTART_DELAY_SECS ) ;
201+ info ! ( "Restarting login/logoff event monitoring" ) ;
202+ }
199203 }
200204 }
201- }
202- } ) ;
205+ } )
206+ . expect ( "Failed to spawn login/logoff monitor thread" ) ;
203207
204208 // Spawn the main gRPC server task
205209 let service_location_manager_clone = service_location_manager. clone ( ) ;
0 commit comments