🔊 improve error handling when opening / closing ports
parent
de4da749f3
commit
e8bb7ab098
|
@ -66,7 +66,13 @@ impl GuiClient <'_> {
|
||||||
|
|
||||||
pub fn close_port (&mut self, port_idx: usize) -> anyhow::Result <()> {
|
pub fn close_port (&mut self, port_idx: usize) -> anyhow::Result <()> {
|
||||||
if let Some (old_instance) = self.forwarding_instances [port_idx].take () {
|
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);
|
self.gui_ports [port_idx].set_forwarding (false);
|
||||||
|
|
|
@ -32,8 +32,13 @@ impl ForwardingInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn close (self) -> anyhow::Result <()> {
|
pub async fn close (self) -> anyhow::Result <()> {
|
||||||
self.shutdown_flag.send (false)?;
|
match self.shutdown_flag.send (false) {
|
||||||
self.task.await??;
|
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 (())
|
Ok (())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue