🔊 improve error handling when opening / closing ports

main
_ 2021-10-10 18:08:25 +00:00
parent de4da749f3
commit e8bb7ab098
2 changed files with 14 additions and 3 deletions

View File

@ -66,7 +66,13 @@ impl GuiClient <'_> {
pub fn close_port (&mut self, port_idx: usize) -> anyhow::Result <()> {
if let Some (old_instance) = self.forwarding_instances [port_idx].take () {
self.rt.block_on (old_instance.close ())?;
self.rt.block_on (async {
old_instance.close ()
.await
.context ("closing ForwardingInstance")?;
Ok::<_, anyhow::Error> (())
})?;
}
self.gui_ports [port_idx].set_forwarding (false);

View File

@ -32,8 +32,13 @@ impl ForwardingInstance {
}
pub async fn close (self) -> anyhow::Result <()> {
self.shutdown_flag.send (false)?;
self.task.await??;
match self.shutdown_flag.send (false) {
Err (_) => warn! ("Trying to gracefully shutdown forwarding task but it appears to already be shut down"),
_ => (),
}
self.task.await
.context ("awaiting ForwardingInstance task")?
.context ("inside ForwardingInstance task")?;
Ok (())
}
}