Skip to content

Commit

Permalink
Do not spawn new tasks per packet.
Browse files Browse the repository at this point in the history
Instead, rely on the channel to rate limit and limit memory usage.
  • Loading branch information
zlogic committed Nov 30, 2024
1 parent a995408 commit b0a9d28
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/ikev2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,7 @@ impl FortiService {
}
};
if !data.is_empty() {
let rt = runtime::Handle::current();
let tx = sessions_tx.clone();
rt.spawn(async move { tx.send(SessionMessage::VpnPacket(data)).await });
let _ = sessions_tx.send(SessionMessage::VpnPacket(data)).await;
}
}
FortiServiceCommand::SendEcho => {
Expand Down Expand Up @@ -1109,9 +1107,7 @@ impl FortiService {

async fn send_packet(&self, data: Vec<u8>) -> Result<(), IKEv2Error> {
if let Some(tx) = self.command_sender.as_ref() {
let rt = runtime::Handle::current();
let tx = tx.clone();
rt.spawn(async move { tx.send(FortiServiceCommand::SendPacket(data)).await });
let _ = tx.send(FortiServiceCommand::SendPacket(data)).await;
Ok(())
} else {
Err("VPN client service is not running".into())
Expand Down

0 comments on commit b0a9d28

Please sign in to comment.