fixed windows service bug

This commit is contained in:
viraladmin 2026-06-01 09:19:47 -06:00
parent 4b66a2bd54
commit 72b894d6cb
2 changed files with 16 additions and 6 deletions

View File

@ -203,7 +203,9 @@ async fn handle_request(
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(),
message: format!(
"Service is not waiting for a wallet key. Current state: {current_state:?}."
),
};
}

View File

@ -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::<Arc<Wallet>>();
let unlocked_node_task: Arc<StdMutex<Option<JoinHandle<()>>>> = 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() {