From 2f197c088150aef7e2652024274cff71de11aa17 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 18 Jul 2024 11:58:21 +0200 Subject: [PATCH 1/3] refactor(udp): add use declaration for tracing debug and error --- quinn-udp/src/unix.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/quinn-udp/src/unix.rs b/quinn-udp/src/unix.rs index 89fc36586..1005ca859 100644 --- a/quinn-udp/src/unix.rs +++ b/quinn-udp/src/unix.rs @@ -13,6 +13,7 @@ use std::{ }; use socket2::SockRef; +use tracing::{debug, error}; use super::{ cmsg, log_sendmsg_error, EcnCodepoint, RecvMeta, Transmit, UdpSockRef, IO_ERROR_LOG_INTERVAL, @@ -87,7 +88,7 @@ impl UdpSocketState { if is_ipv4 || !io.only_v6()? { if let Err(err) = set_socket_option(&*io, libc::IPPROTO_IP, libc::IP_RECVTOS, OPTION_ON) { - tracing::debug!("Ignoring error setting IP_RECVTOS on socket: {err:?}",); + debug!("Ignoring error setting IP_RECVTOS on socket: {err:?}",); } } @@ -283,7 +284,7 @@ fn send( // Prevent new transmits from being scheduled using GSO. Existing GSO transmits // may already be in the pipeline, so we need to tolerate additional failures. if state.max_gso_segments() > 1 { - tracing::error!("got transmit error, halting segmentation offload"); + error!("got transmit error, halting segmentation offload"); state .max_gso_segments .store(1, std::sync::atomic::Ordering::Relaxed); From df584d3ca4df4bfb6945fb6908fed87ef2b7789e Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 18 Jul 2024 12:01:07 +0200 Subject: [PATCH 2/3] deps(udp): make tracing optional and add optional log This commit makes the `tracing` dependency in `quinn-udp` optional, but enabled by default. In additional it adds optional logging via the `log` crate, enabled through the `direct-log` feature. `tracing` takes precedence over `native-log`. --- Cargo.toml | 1 + quinn-proto/Cargo.toml | 2 +- quinn-udp/Cargo.toml | 8 +++++--- quinn-udp/src/lib.rs | 8 ++++++++ quinn-udp/src/unix.rs | 8 +++++++- quinn/Cargo.toml | 4 ++-- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9413c5943..e1b38c772 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ futures-io = "0.3.19" hdrhistogram = { version = "7.2", default-features = false } hex-literal = "0.4" lazy_static = "1" +log = "0.4" once_cell = "1.19" pin-project-lite = "0.2" rand = "0.8" diff --git a/quinn-proto/Cargo.toml b/quinn-proto/Cargo.toml index 5b790b0d2..5ce7e916d 100644 --- a/quinn-proto/Cargo.toml +++ b/quinn-proto/Cargo.toml @@ -20,7 +20,7 @@ ring = ["dep:ring"] # Enable rustls ring provider and direct ring usage # Provides `ClientConfig::with_platform_verifier()` convenience method platform-verifier = ["dep:rustls-platform-verifier"] -# Write logs via the `log` crate when no `tracing` subscriber exists +# Configure `tracing` to log events via `log` if no `tracing` subscriber exists. log = ["tracing/log"] [dependencies] diff --git a/quinn-udp/Cargo.toml b/quinn-udp/Cargo.toml index 293080297..f739f11e4 100644 --- a/quinn-udp/Cargo.toml +++ b/quinn-udp/Cargo.toml @@ -14,14 +14,16 @@ workspace = ".." all-features = true [features] -default = ["log"] -# Write logs via the `log` crate when no `tracing` subscriber exists +default = ["tracing", "log"] +# Configure `tracing` to log events via `log` if no `tracing` subscriber exists. log = ["tracing/log"] +direct-log = ["dep:log"] [dependencies] libc = "0.2.113" +log = { workspace = true, optional = true } socket2 = { workspace = true } -tracing = { workspace = true } +tracing = { workspace = true, optional = true } [target.'cfg(windows)'.dependencies] once_cell = { workspace = true } diff --git a/quinn-udp/src/lib.rs b/quinn-udp/src/lib.rs index 4d8c5d404..0337b9c05 100644 --- a/quinn-udp/src/lib.rs +++ b/quinn-udp/src/lib.rs @@ -37,6 +37,9 @@ use std::{ time::{Duration, Instant}, }; +#[cfg(all(feature = "direct-log", not(feature = "tracing")))] +use log::warn; +#[cfg(feature = "tracing")] use tracing::warn; #[cfg(any(unix, windows))] @@ -126,6 +129,7 @@ const IO_ERROR_LOG_INTERVAL: Duration = std::time::Duration::from_secs(60); /// /// Logging will only be performed if at least [`IO_ERROR_LOG_INTERVAL`] /// has elapsed since the last error was logged. +#[cfg(any(feature = "tracing", feature = "direct-log"))] fn log_sendmsg_error( last_send_error: &Mutex, err: impl core::fmt::Debug, @@ -141,6 +145,10 @@ fn log_sendmsg_error( } } +// No-op +#[cfg(not(any(feature = "tracing", feature = "direct-log")))] +fn log_sendmsg_error(_: &Mutex, _: impl core::fmt::Debug, _: &Transmit) {} + /// A borrowed UDP socket /// /// On Unix, constructible via `From`. On Windows, constructible via `From 1 { + #[cfg(any(feature = "tracing", feature = "direct-log"))] error!("got transmit error, halting segmentation offload"); state .max_gso_segments diff --git a/quinn/Cargo.toml b/quinn/Cargo.toml index db421b434..add7bb7ce 100644 --- a/quinn/Cargo.toml +++ b/quinn/Cargo.toml @@ -27,7 +27,7 @@ runtime-tokio = ["tokio/time", "tokio/rt", "tokio/net"] runtime-async-std = ["async-io", "async-std"] runtime-smol = ["async-io", "smol"] -# Write logs via the `log` crate when no `tracing` subscriber exists +# Configure `tracing` to log events via `log` if no `tracing` subscriber exists. log = ["tracing/log", "proto/log", "udp/log"] [dependencies] @@ -45,7 +45,7 @@ socket2 = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true } tokio = { workspace = true } -udp = { package = "quinn-udp", path = "../quinn-udp", version = "0.5", default-features = false } +udp = { package = "quinn-udp", path = "../quinn-udp", version = "0.5", default-features = false, features = ["tracing"] } [dev-dependencies] anyhow = { workspace = true } From 46944db2b486555bcd74ad855f73d881f659fbed Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 19 Jul 2024 11:04:48 +0200 Subject: [PATCH 3/3] chore: increase quinn-udp version to v0.5.3 --- quinn-udp/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quinn-udp/Cargo.toml b/quinn-udp/Cargo.toml index f739f11e4..333b1aeaa 100644 --- a/quinn-udp/Cargo.toml +++ b/quinn-udp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "quinn-udp" -version = "0.5.2" +version = "0.5.3" edition = "2021" rust-version = "1.66" license = "MIT OR Apache-2.0"