Skip to content

Commit

Permalink
fix: gracefully shutdown issue
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Jul 26, 2024
1 parent 7676fce commit 7cdd806
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions nyanpasu-utils/src/core/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,27 +280,34 @@ impl CoreInstance {
.await
.map_err(|e| CoreInstanceError::Io(std::io::Error::new(std::io::ErrorKind::Other, e)))
{
Ok(_) => loop {
if let Some(state) = instance.try_wait()? {
if !state.success() {
tracing::warn!("instance terminated with error: {:?}", state);
Ok(_) => {
for _ in 0..20 {
if let Some(state) = instance.try_wait()? {
if !state.success() {
tracing::warn!("instance terminated with error: {:?}", state);
}
return Ok(());
}
return Ok(());
std::thread::sleep(Duration::from_millis(100));
}
std::thread::sleep(Duration::from_millis(100));
},
}
Err(err) => {
tracing::warn!("Failed to gracefully kill instance: {:?}", err);
}
}
instance.kill()?;
// poll the instance until it is terminated
loop {
for i in 0..30 {
if let Some(state) = instance.try_wait()? {
if !state.success() {
tracing::warn!("instance terminated with error: {:?}", state);
}
break;
} else if i == 29 {
return Err(CoreInstanceError::Io(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to kill instance: force kill timeout",
)));
}
std::thread::sleep(Duration::from_millis(100));
}
Expand Down
2 changes: 1 addition & 1 deletion os-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn gracefully_kill(pid: u32) -> std::io::Result<()> {
std::io::ErrorKind::Other,
format!("GenerateConsoleCtrlEvent failed: {:?}", e),
)
});
})?;
}
Ok(())
}
Expand Down

0 comments on commit 7cdd806

Please sign in to comment.