From 9536b8116cd812dbec758a89ad04fe24e505e038 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Sat, 16 Nov 2024 06:19:41 +0000 Subject: [PATCH] fix: don't exit TUN thread on errors (#7354) I noticed that in case there is an error when reading from the TUN device, we currently exit that thread and we don't have a mechanism at the moment to restart it. Discarding the thread also means we can no longer send new instances of `Tun` into it. Instead of exiting the thread, we now just log the error and continue. In case the error was caused by the FD being closed, we discard the instance of `Tun` and wait for a new one. --- rust/connlib/tunnel/src/device_channel.rs | 2 ++ rust/connlib/tunnel/src/io.rs | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/rust/connlib/tunnel/src/device_channel.rs b/rust/connlib/tunnel/src/device_channel.rs index bb2c0bea0..9a9f265a6 100644 --- a/rust/connlib/tunnel/src/device_channel.rs +++ b/rust/connlib/tunnel/src/device_channel.rs @@ -41,6 +41,8 @@ impl Device { let n = std::task::ready!(tun.poll_read(ip_packet.buf(), cx))?; if n == 0 { + self.tun = None; + return Poll::Ready(Err(io::Error::new( io::ErrorKind::UnexpectedEof, "device is closed", diff --git a/rust/connlib/tunnel/src/io.rs b/rust/connlib/tunnel/src/io.rs index 59f068dba..42516c00d 100644 --- a/rust/connlib/tunnel/src/io.rs +++ b/rust/connlib/tunnel/src/io.rs @@ -1,6 +1,6 @@ use crate::{device_channel::Device, dns, sockets::Sockets}; use domain::base::Message; -use firezone_logging::{err_with_sources, std_dyn_err, telemetry_event, telemetry_span}; +use firezone_logging::{err_with_sources, telemetry_event, telemetry_span}; use futures::{ future::{self, Either}, stream, Stream, StreamExt, @@ -379,10 +379,9 @@ async fn tun_send_recv( } Either::Right((Err(e), _)) => { tracing::debug!( - error = std_dyn_err(&e), - "Failed to read packet from TUN device" + "Failed to read packet from TUN device: {}", + err_with_sources(&e) ); - return; } }; }