mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
fix(firezone-tunnel(windows)): don't panic if the sending ring buffer is full (#3544)
I never saw this replicate, but in theory it could happen. This PR just drops packets while the ring buffer is full. Closes #3518
This commit is contained in:
@@ -222,14 +222,19 @@ impl Tun {
|
||||
}
|
||||
|
||||
fn write(&self, bytes: &[u8]) -> io::Result<usize> {
|
||||
// TODO: If the ring buffer is full, don't panic, just return Ok(None) or an error or whatever the Unix impls do.
|
||||
// <https://github.com/firezone/firezone/issues/3518>
|
||||
// Make sure this doesn't block.
|
||||
let mut pkt = self
|
||||
.session
|
||||
.allocate_send_packet(bytes.len().try_into().unwrap())
|
||||
.unwrap();
|
||||
let len = bytes
|
||||
.len()
|
||||
.try_into()
|
||||
.expect("Packet length should fit into u16");
|
||||
|
||||
let Ok(mut pkt) = self.session.allocate_send_packet(len) else {
|
||||
// Ring buffer is full, just drop the packet since we're at the IP layer
|
||||
return Ok(0);
|
||||
};
|
||||
|
||||
pkt.bytes_mut().copy_from_slice(bytes);
|
||||
// `send_packet` cannot fail to enqueue the packet, since we already allocated
|
||||
// space in the ring buffer.
|
||||
self.session.send_packet(pkt);
|
||||
Ok(bytes.len())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user