diff --git a/boltconn/src/adapter/wireguard.rs b/boltconn/src/adapter/wireguard.rs index 826ba78..cf32db9 100644 --- a/boltconn/src/adapter/wireguard.rs +++ b/boltconn/src/adapter/wireguard.rs @@ -233,16 +233,22 @@ impl Endpoint { }); } - let name_clone = name.to_string(); - tokio::spawn(async move { - // kill all coroutine - let _ = stop_recv.recv().await; - indi_write.abort(); - wg_out.abort(); - wg_in.abort(); - wg_tick.abort(); - tracing::trace!("[WireGuard] connection #{} killed", name_clone); - }); + { + let name = name.to_string(); + let stack = smol_stack.clone(); + tokio::spawn(async move { + // kill all coroutine + let _ = stop_recv.recv().await; + indi_write.abort(); + wg_out.abort(); + wg_in.abort(); + wg_tick.abort(); + // reset smol stack to drop all channel sender, + // so the receiver can report errors correctly + stack.lock().await.terminate_all(); + tracing::trace!("[WireGuard] connection #{} killed", name); + }); + } tracing::info!("[WireGuard] Established master connection #{}", name); diff --git a/boltconn/src/transport/smol.rs b/boltconn/src/transport/smol.rs index f74835e..09dd5fd 100644 --- a/boltconn/src/transport/smol.rs +++ b/boltconn/src/transport/smol.rs @@ -700,6 +700,12 @@ impl SmolStack { } }); } + + /// Terminate all connections with fatal errors + pub fn terminate_all(&mut self) { + self.tcp_conn.clear(); + self.udp_conn.clear(); + } } // -----------------------------------------------------------------------------------