fixed windows service bug
This commit is contained in:
parent
4b66a2bd54
commit
72b894d6cb
|
|
@ -200,12 +200,14 @@ async fn handle_request(
|
||||||
UnlockPipeRequest::SubmitKey { wallet_key } => {
|
UnlockPipeRequest::SubmitKey { wallet_key } => {
|
||||||
// The service only accepts a wallet key while it is still in the locked
|
// 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.
|
// waiting state, and it validates the key before allowing normal startup.
|
||||||
let current_state = *service_state.read().await;
|
let current_state = *service_state.read().await;
|
||||||
if !matches!(current_state, ServiceWaitState::WaitingForUnlock) {
|
if !matches!(current_state, ServiceWaitState::WaitingForUnlock) {
|
||||||
return UnlockPipeResponse::Error {
|
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:?}."
|
||||||
}
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
match Wallet::try_obtain_wallet(wallet_key, None).await {
|
match Wallet::try_obtain_wallet(wallet_key, None).await {
|
||||||
Ok(wallet) => {
|
Ok(wallet) => {
|
||||||
|
|
|
||||||
|
|
@ -473,6 +473,7 @@ fn run_service() -> windows_service::Result<()> {
|
||||||
|
|
||||||
let service_state = Arc::new(RwLock::new(ServiceWaitState::WaitingForUnlock));
|
let service_state = Arc::new(RwLock::new(ServiceWaitState::WaitingForUnlock));
|
||||||
let service_state_for_pipe = service_state.clone();
|
let service_state_for_pipe = service_state.clone();
|
||||||
|
let service_state_for_loop = service_state.clone();
|
||||||
let shutdown_for_pipe = shutdown.clone();
|
let shutdown_for_pipe = shutdown.clone();
|
||||||
let (unlock_tx, mut unlock_rx) = mpsc::unbounded_channel::<Arc<Wallet>>();
|
let (unlock_tx, mut unlock_rx) = mpsc::unbounded_channel::<Arc<Wallet>>();
|
||||||
let unlocked_node_task: Arc<StdMutex<Option<JoinHandle<()>>>> = Arc::new(StdMutex::new(None));
|
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 {
|
if let Some(wallet) = maybe_wallet {
|
||||||
// Once the wallet key is accepted, the shared unlocked-node
|
// Once the wallet key is accepted, the shared unlocked-node
|
||||||
// runtime is launched inside the service process itself.
|
// 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 {
|
let handle = tokio::spawn(async move {
|
||||||
if let Err(err) = run_unlocked_node(wallet, false).await {
|
if let Err(err) = run_unlocked_node(wallet, false).await {
|
||||||
error!("Unlocked Windows service node failed during startup: {err}");
|
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() {
|
if let Ok(mut task_slot) = unlocked_node_task_for_loop.lock() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue