Correct shutdown double panic

pull/118/head
Chip Senkbeil 2 years ago
parent 94326618c3
commit 33a30d98f0
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -3,6 +3,7 @@ use derive_more::{Deref, DerefMut};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use rstest::*; use rstest::*;
use std::{ use std::{
io,
path::PathBuf, path::PathBuf,
process::{Child, Command as StdCommand, Stdio}, process::{Child, Command as StdCommand, Stdio},
thread, thread,
@ -129,7 +130,7 @@ impl DistantManagerCtx {
} }
} }
pub fn shutdown(&self) { pub fn shutdown(&self) -> io::Result<()> {
// Send a shutdown request to the manager // Send a shutdown request to the manager
let mut shutdown_cmd = StdCommand::new(bin_path()); let mut shutdown_cmd = StdCommand::new(bin_path());
shutdown_cmd shutdown_cmd
@ -153,10 +154,15 @@ impl DistantManagerCtx {
eprintln!("Spawning shutdown cmd: {shutdown_cmd:?}"); eprintln!("Spawning shutdown cmd: {shutdown_cmd:?}");
let output = shutdown_cmd.output().expect("Failed to shutdown server"); let output = shutdown_cmd.output().expect("Failed to shutdown server");
if !output.status.success() { if !output.status.success() {
panic!( Err(io::Error::new(
"Failed to shutdown: {}", io::ErrorKind::Other,
String::from_utf8_lossy(&output.stderr) format!(
); "Failed to shutdown: {}",
String::from_utf8_lossy(&output.stderr)
),
))
} else {
Ok(())
} }
} }
@ -228,7 +234,7 @@ impl Drop for DistantManagerCtx {
/// Kills manager upon drop /// Kills manager upon drop
fn drop(&mut self) { fn drop(&mut self) {
// Attempt to shutdown gracefully, forcing a kill otherwise // Attempt to shutdown gracefully, forcing a kill otherwise
if std::panic::catch_unwind(|| self.shutdown()).is_err() { if self.shutdown().is_err() {
let _ = self.manager.kill(); let _ = self.manager.kill();
let _ = self.manager.wait(); let _ = self.manager.wait();
} }

Loading…
Cancel
Save