From 72b894d6cb58edef3c9b2dc1a24e76d5353e06dd Mon Sep 17 00:00:00 2001 From: viraladmin <00purple@gmail.com> Date: Mon, 1 Jun 2026 09:19:47 -0600 Subject: [PATCH] fixed windows service bug --- src/startup/unlock_pipe.rs | 14 ++++++++------ src/startup/windows_service.rs | 8 ++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/startup/unlock_pipe.rs b/src/startup/unlock_pipe.rs index b3b662d..97476df 100644 --- a/src/startup/unlock_pipe.rs +++ b/src/startup/unlock_pipe.rs @@ -200,12 +200,14 @@ async fn handle_request( UnlockPipeRequest::SubmitKey { wallet_key } => { // The service only accepts a wallet key while it is still in the locked // waiting state, and it validates the key before allowing normal startup. - let current_state = *service_state.read().await; - if !matches!(current_state, ServiceWaitState::WaitingForUnlock) { - return UnlockPipeResponse::Error { - message: "Service is not waiting for a wallet key.".to_string(), - }; - } + let current_state = *service_state.read().await; + if !matches!(current_state, ServiceWaitState::WaitingForUnlock) { + return UnlockPipeResponse::Error { + message: format!( + "Service is not waiting for a wallet key. Current state: {current_state:?}." + ), + }; + } match Wallet::try_obtain_wallet(wallet_key, None).await { Ok(wallet) => { diff --git a/src/startup/windows_service.rs b/src/startup/windows_service.rs index 28eefd4..8ecd7b3 100644 --- a/src/startup/windows_service.rs +++ b/src/startup/windows_service.rs @@ -473,6 +473,7 @@ fn run_service() -> windows_service::Result<()> { let service_state = Arc::new(RwLock::new(ServiceWaitState::WaitingForUnlock)); let service_state_for_pipe = service_state.clone(); + let service_state_for_loop = service_state.clone(); let shutdown_for_pipe = shutdown.clone(); let (unlock_tx, mut unlock_rx) = mpsc::unbounded_channel::>(); let unlocked_node_task: Arc>>> = Arc::new(StdMutex::new(None)); @@ -514,10 +515,17 @@ fn run_service() -> windows_service::Result<()> { if let Some(wallet) = maybe_wallet { // Once the wallet key is accepted, the shared unlocked-node // runtime is launched inside the service process itself. + let service_state_for_node = service_state_for_loop.clone(); + let shutdown_for_node = shutdown_for_service.clone(); let handle = tokio::spawn(async move { if let Err(err) = run_unlocked_node(wallet, false).await { error!("Unlocked Windows service node failed during startup: {err}"); } + + if !shutdown_for_node.load(AtomicOrdering::SeqCst) { + let mut state = service_state_for_node.write().await; + *state = ServiceWaitState::WaitingForUnlock; + } }); if let Ok(mut task_slot) = unlocked_node_task_for_loop.lock() {