Skip to content

Commit

Permalink
CVPN-956: handling of Full error on tun io-uring send
Browse files Browse the repository at this point in the history
Treating tun io-uring Full error as OK scenario.
It is effectively the same scenario as a buffer in a network switch/router filling up so dropping the traffic is appropriate, higher level protocols (e.g. TCP) running over the tunnel will use their congestion control algorithms to adjust their send rate.
  • Loading branch information
kp-stanislav-baiduzhyi committed Jun 19, 2024
1 parent ba85d90 commit a8864d9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lightway-app-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tokio-eventfd = "0.2.1"
dashmap = "5.5.3"
thiserror = "1.0.57"
tokio-tun = "0.11.2"
metrics = "0.23.0"

[[example]]
name = "udprelay"
Expand Down
17 changes: 12 additions & 5 deletions lightway-app-utils/src/iouring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{
};
use tokio::{io::AsyncReadExt, sync::Semaphore};
use tokio_eventfd::EventFd;
use crate::metrics::tun_iouring_data_dropped;

const REGISTERED_FD_INDEX: u32 = 0;
const IOURING_SQPOLL_IDLE_TIME: u32 = 100;
Expand Down Expand Up @@ -190,11 +191,17 @@ impl<T: AsRawFd> IOUring<T> {

/// Try Send packet to Tun device
pub fn try_send(&self, buf: BytesMut) -> IOUringResult<()> {
self.inner
.send_q
.tx
.try_send(buf)
.map_err(IOUringError::SendError)
let try_send_res = self.inner.send_q.tx.try_send(buf);
match try_send_res {
Ok(()) => Ok(()),
Err(e) if e.is_full() => {
// it is effectively the same scenario as a buffer in a network
// switch/router filling up so dropping the traffic is appropriate
tun_iouring_data_dropped();
Ok(())
}
Err(e) => Err(IOUringError::SendError(e)),
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lightway-app-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ pub use iouring::IOUring;

pub use tun::Tun;

mod metrics;
mod utils;
pub use utils::is_file_path_valid;
8 changes: 8 additions & 0 deletions lightway-app-utils/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use metrics::counter;

const METRIC_TUN_IOURING_DATA_DROPPED: &str = "tun_iouring_data_dropped";

/// Counter for "sending into a full channel" type of error ([`async_channel::TrySendError::Full`])
pub(crate) fn tun_iouring_data_dropped() {
counter!(METRIC_TUN_IOURING_DATA_DROPPED).increment(1);
}

0 comments on commit a8864d9

Please sign in to comment.