Skip to content

Commit

Permalink
fix(wireguard): remove all tasks in smol side when wireguard side exits
Browse files Browse the repository at this point in the history
  • Loading branch information
XOR-op committed Oct 14, 2024
1 parent e18ce17 commit 1098b4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
26 changes: 16 additions & 10 deletions boltconn/src/adapter/wireguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions boltconn/src/transport/smol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

// -----------------------------------------------------------------------------------
Expand Down

0 comments on commit 1098b4b

Please sign in to comment.