From 14f229f2593d4071e44f12440012bef38b78222b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 17 Oct 2026 08:02:43 -0700 Subject: [PATCH] fix(quic): report unreachable sends to moq-quic, and stop the server socket swallowing them Co-Authored-By: Claude Opus 5.5 --- rs/moq-quic/README.md | 2 +- rs/moq-quic/src/connection/mod.rs | 12 +++++ rs/moq-quic/src/tests/mod.rs | 43 ++++++++++++++++++ rs/moq-sock/src/udp/mod.rs | 32 -------------- rs/moq-sock/src/udp/unix.rs | 42 ++---------------- rs/moq-sock/src/udp/wasi.rs | 35 ++------------- rs/moq-sock/src/udp/windows.rs | 41 +---------------- rs/moq-tokio/src/quic/backend.rs | 49 ++++++++++++++++++--- rs/moq-tokio/src/quic/driver/connection.rs | 38 ++++------------ rs/moq-tokio/src/quic/driver/mod.rs | 1 + rs/moq-tokio/src/quic/driver/runtime/mod.rs | 34 +++++++------- rs/moq-uring/src/quic/driver/connection.rs | 12 ----- rs/moq-uring/src/quic/driver/endpoint.rs | 12 ++--- 13 files changed, 142 insertions(+), 211 deletions(-) diff --git a/rs/moq-quic/README.md b/rs/moq-quic/README.md index 8d12d1e703a..5249dca438a 100644 --- a/rs/moq-quic/README.md +++ b/rs/moq-quic/README.md @@ -60,7 +60,7 @@ Changes on top of the upstream commit, besides the renames: We extend it to resend batches built before GSO was halted too, which upstream's version drops, and to log only the first rejection. A `WouldBlock` partway through the resend makes the caller retry the whole batch, duplicating the datagrams already sent; QUIC drops the duplicates. Drop it if upstream lands [quinn#2748](https://github.com/quinn-rs/quinn/pull/2748) and we cherry-pick that. -- **Unreachable sends** (`moq_sock::udp::is_unreachable_err`, the driver's `UdpSenderHelper`): `ENETUNREACH`, `EHOSTUNREACH` and `ENETDOWN` reach the connection instead of being logged as loss. A handshaking connection fails at once with `NO_VIABLE_PATH`, so a dial race moves to the next address; an established one still counts them as loss. Addresses [quinn#2766](https://github.com/quinn-rs/quinn/issues/2766), reworked from [kixelated/quinn#3](https://github.com/kixelated/quinn/pull/3). +- **Unreachable sends** (`Connection::handle_unreachable`): a driver reports a send that fails with `ENETUNREACH`, `EHOSTUNREACH` or `ENETDOWN` (`moq_sock::udp::is_unreachable_err`) instead of logging it as loss. A handshaking connection fails at once with `NO_VIABLE_PATH` and sends no CONNECTION\_CLOSE, so a dial race moves to the next address; an established one ignores it and the datagram counts as loss. Addresses [quinn#2766](https://github.com/quinn-rs/quinn/issues/2766), reworked from [kixelated/quinn#3](https://github.com/kixelated/quinn/pull/3). - Apple fast-path fallback preserves the segmentation of batches prepared before the fast path was disabled, including when a private symbol is unavailable. - Discarding Initial or Handshake keys resets the PTO backoff, as RFC 9002 A.11 does, so a client's Initial backoff no longer delays the retransmission of a lost Finished. Also [moq-dev/noq#32](https://github.com/moq-dev/noq/pull/32); not offered upstream yet. - `TransportConfig::handshake_idle_timeout` (default 10s, as msquic's `HandshakeIdleTimeoutMs`) governs the idle timer until the handshake completes, and the negotiated idle timeout takes over once established. A 2s idle timeout otherwise expires 3x the initial PTO in, just before the second Initial probe, leaving a client two flights. A server also drops an Initial left waiting for `accept` past it, and a deadline too far out to represent never fires instead of panicking. Also [moq-dev/noq#34](https://github.com/moq-dev/noq/pull/34), whose third change (the handshake idle timeout picks noq's idle-based PTO interval cap) has nothing to apply to here, since quinn's PTO backoff has no such cap. diff --git a/rs/moq-quic/src/connection/mod.rs b/rs/moq-quic/src/connection/mod.rs index b2f5fdb6049..57d228b30ae 100644 --- a/rs/moq-quic/src/connection/mod.rs +++ b/rs/moq-quic/src/connection/mod.rs @@ -1353,6 +1353,18 @@ impl Connection { ) } + /// Report that a send to the peer found no route, such as `ENETUNREACH` + /// + /// A handshake can never finish, so it fails at once with `NO_VIABLE_PATH`, sending no + /// CONNECTION_CLOSE the peer could not receive anyway. An established connection is left + /// alone, since a route that drops for a moment (a client switching networks) comes back, so + /// the datagram is just lost. + pub fn handle_unreachable(&mut self) { + if self.state.is_handshake() { + self.kill(TransportError::NO_VIABLE_PATH("no route to the peer").into()); + } + } + fn close_inner(&mut self, now: Instant, reason: Close) { let was_closed = self.state.is_closed(); if !was_closed { diff --git a/rs/moq-quic/src/tests/mod.rs b/rs/moq-quic/src/tests/mod.rs index eb447b86c43..91b1cec7e16 100644 --- a/rs/moq-quic/src/tests/mod.rs +++ b/rs/moq-quic/src/tests/mod.rs @@ -2189,6 +2189,49 @@ fn idle_timeout() { ); } +#[test] +fn unreachable_handshake_fails_with_no_viable_path() { + let _guard = subscribe(); + let mut pair = Pair::default(); + let client_ch = pair.begin_connect(client_config()); + + pair.client_conn_mut(client_ch).handle_unreachable(); + + let conn = pair.client_conn_mut(client_ch); + assert!(conn.is_drained()); + assert_matches!( + conn.poll(), + Some(Event::ConnectionLost { + reason: ConnectionError::TransportError(TransportError { + code: TransportErrorCode::NO_VIABLE_PATH, + .. + }), + }) + ); + // Not even a CONNECTION_CLOSE goes out. + pair.drive(); + pair.server.assert_no_accept(); +} + +#[test] +fn unreachable_is_loss_once_established() { + let _guard = subscribe(); + let mut pair = Pair::default(); + let (client_ch, server_ch) = pair.connect(); + + pair.client_conn_mut(client_ch).handle_unreachable(); + + assert!(!pair.client_conn_mut(client_ch).is_closed()); + assert_matches!(pair.client_conn_mut(client_ch).poll(), None); + let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + pair.client_send(client_ch, s).write(b"hello").unwrap(); + pair.drive(); + assert_matches!( + pair.server_conn_mut(server_ch).poll(), + Some(Event::Stream(StreamEvent::Opened { dir: Dir::Uni })) + ); +} + #[test] fn connection_close_sends_acks() { let _guard = subscribe(); diff --git a/rs/moq-sock/src/udp/mod.rs b/rs/moq-sock/src/udp/mod.rs index ccdaff88fc3..6df8feee73f 100644 --- a/rs/moq-sock/src/udp/mod.rs +++ b/rs/moq-sock/src/udp/mod.rs @@ -45,8 +45,6 @@ use std::{ net::UdpSocket, os::fd::{AsRawFd, FromRawFd}, }; -#[cfg(not(wasm_browser))] -use std::{sync::Mutex, time::Instant}; #[cfg(windows)] use windows_sys::Win32::Networking::WinSock; @@ -267,36 +265,6 @@ pub fn is_unreachable_err(err: &io::Error) -> bool { ) } -/// Log at most 1 IO error per minute -#[cfg(not(wasm_browser))] -const IO_ERROR_LOG_INTERVAL: Duration = Duration::from_secs(60); - -/// Logs a warning message when sendmsg fails -/// -/// Logging will only be performed if at least [`IO_ERROR_LOG_INTERVAL`] -/// has elapsed since the last error was logged. -#[cfg(not(wasm_browser))] -fn log_sendmsg_error( - last_send_error: &Mutex, - err: impl core::fmt::Debug, - transmit: &Transmit<'_>, -) { - let now = Instant::now(); - let last_send_error = &mut *last_send_error.lock().expect("poisend lock"); - if now.saturating_duration_since(*last_send_error) > IO_ERROR_LOG_INTERVAL { - *last_send_error = now; - log::warn!( - "sendmsg error: {:?}, Transmit: {{ destination: {:?}, src_ip: {:?}, ecn: {:?}, len: {:?}, segment_size: {:?} }}", - err, - transmit.destination, - transmit.src_ip, - transmit.ecn, - transmit.contents.len(), - transmit.segment_size - ); - } -} - /// A borrowed UDP socket /// /// On Unix, constructible via `From`. On Windows, constructible via `From, max_gso_segments: AtomicUsize, gro_segments: usize, may_fragment: bool, @@ -197,9 +190,7 @@ impl UdpSocketState { let _ = io.set_send_buffer_size(Self::MIN_SAFE_SNDBUF); } - let now = Instant::now(); Ok(Self { - last_send_error: Mutex::new(now.checked_sub(2 * IO_ERROR_LOG_INTERVAL).unwrap_or(now)), max_gso_segments: AtomicUsize::new(gso::max_gso_segments(&*io)), gro_segments, may_fragment, @@ -211,33 +202,6 @@ impl UdpSocketState { }) } - /// Sends a [`Transmit`] on the given socket - /// - /// This function will only ever return errors of kind [`io::ErrorKind::WouldBlock`]. - /// All other errors will be logged and converted to `Ok`. - /// - /// UDP transmission errors are considered non-fatal because higher-level protocols must - /// employ retransmits and timeouts anyway in order to deal with UDP's unreliable nature. - /// Thus, logging is most likely the only thing you can do with these errors. - /// - /// If you would like to handle these errors yourself, use [`UdpSocketState::try_send`] - /// instead. - #[deprecated(note = "silences I/O errors; use `UdpSocketState::try_send() instead")] - pub fn send(&self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> { - match send(self, socket.0, transmit) { - Ok(()) => Ok(()), - Err(e) if e.kind() == io::ErrorKind::WouldBlock => Err(e), - // - EMSGSIZE is expected for MTU probes. Future work might be able to avoid - // these by automatically clamping the MTUD upper bound to the interface MTU. - Err(e) if e.raw_os_error() == Some(libc::EMSGSIZE) => Ok(()), - Err(e) => { - log_sendmsg_error(&self.last_send_error, e, transmit); - - Ok(()) - } - } - } - /// Sends a [`Transmit`] on the given socket without any additional error handling pub fn try_send(&self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> { send(self, socket.0, transmit) diff --git a/rs/moq-sock/src/udp/wasi.rs b/rs/moq-sock/src/udp/wasi.rs index 68532e56a36..7a3b455160c 100644 --- a/rs/moq-sock/src/udp/wasi.rs +++ b/rs/moq-sock/src/udp/wasi.rs @@ -1,52 +1,23 @@ use std::{ io::{self, IoSliceMut}, mem::MaybeUninit, - sync::Mutex, - time::Instant, }; -use super::{IO_ERROR_LOG_INTERVAL, RecvMeta, Transmit, UdpSockRef, log_sendmsg_error}; +use super::{RecvMeta, Transmit, UdpSockRef}; /// UDP socket interface for WASI /// /// `wasi:sockets` exposes none of this crate's advanced features, so they are stubbed out. #[derive(Debug)] pub struct UdpSocketState { - last_send_error: Mutex, + _private: (), } impl UdpSocketState { pub fn new(socket: UdpSockRef<'_>) -> io::Result { socket.set_nonblocking(true)?; - let now = Instant::now(); - Ok(Self { - last_send_error: Mutex::new(now.checked_sub(2 * IO_ERROR_LOG_INTERVAL).unwrap_or(now)), - }) - } - - /// Sends a [`Transmit`] on the given socket. - /// - /// This function will only ever return errors of kind [`io::ErrorKind::WouldBlock`]. - /// All other errors will be logged and converted to `Ok`. - /// - /// UDP transmission errors are considered non-fatal because higher-level protocols must - /// employ retransmits and timeouts anyway in order to deal with UDP's unreliable nature. - /// Thus, logging is most likely the only thing you can do with these errors. - /// - /// If you would like to handle these errors yourself, use [`UdpSocketState::try_send`] - /// instead. - #[deprecated(note = "silences I/O errors; use `UdpSocketState::try_send() instead")] - pub fn send(&self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> { - match send(socket, transmit) { - Ok(()) => Ok(()), - Err(e) if e.kind() == io::ErrorKind::WouldBlock => Err(e), - Err(e) => { - log_sendmsg_error(&self.last_send_error, e, transmit); - - Ok(()) - } - } + Ok(Self { _private: () }) } /// Sends a [`Transmit`] on the given socket without any additional error handling. diff --git a/rs/moq-sock/src/udp/windows.rs b/rs/moq-sock/src/udp/windows.rs index 0c72f6b6245..5773905c30f 100644 --- a/rs/moq-sock/src/udp/windows.rs +++ b/rs/moq-sock/src/udp/windows.rs @@ -4,21 +4,16 @@ use std::{ net::{IpAddr, Ipv4Addr}, os::windows::io::AsRawSocket, ptr, - sync::{ - Mutex, - atomic::{AtomicUsize, Ordering}, - }, - time::Instant, + sync::atomic::{AtomicUsize, Ordering}, }; use libc::{c_int, c_uint}; use windows_sys::Win32::Networking::WinSock; use crate::udp::{ - EcnCodepoint, IO_ERROR_LOG_INTERVAL, RecvMeta, Transmit, UdpSockRef, + EcnCodepoint, RecvMeta, Transmit, UdpSockRef, cmsg::{self, CMsgHdr}, log::debug, - log_sendmsg_error, }; /// QUIC-friendly UDP socket for Windows @@ -26,7 +21,6 @@ use crate::udp::{ /// Unlike a standard Windows UDP socket, this allows ECN bits to be read and written. #[derive(Debug)] pub struct UdpSocketState { - last_send_error: Mutex, max_gso_segments: AtomicUsize, /// Whether the underlying Winsock provider supports IPv4 ECN socket options/control messages. @@ -152,9 +146,7 @@ impl UdpSocketState { } } - let now = Instant::now(); Ok(Self { - last_send_error: Mutex::new(now.checked_sub(2 * IO_ERROR_LOG_INTERVAL).unwrap_or(now)), max_gso_segments: AtomicUsize::new(max_gso_segments(&*socket.0)), ecn_v4_supported, ecn_v6_supported, @@ -184,35 +176,6 @@ impl UdpSocketState { ) } - /// Sends a [`Transmit`] on the given socket. - /// - /// This function will only ever return errors of kind [`io::ErrorKind::WouldBlock`]. - /// All other errors will be logged and converted to `Ok`. - /// - /// UDP transmission errors are considered non-fatal because higher-level protocols must - /// employ retransmits and timeouts anyway in order to deal with UDP's unreliable nature. - /// Thus, logging is most likely the only thing you can do with these errors. - /// - /// If you would like to handle these errors yourself, use [`UdpSocketState::try_send`] - /// instead. - #[deprecated(note = "silences I/O errors; use `UdpSocketState::try_send() instead")] - pub fn send(&self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> { - match send( - socket, - transmit, - self.ecn_v4_supported, - self.ecn_v6_supported, - ) { - Ok(()) => Ok(()), - Err(e) if e.kind() == io::ErrorKind::WouldBlock => Err(e), - Err(e) => { - log_sendmsg_error(&self.last_send_error, e, transmit); - - Ok(()) - } - } - } - /// Sends a [`Transmit`] on the given socket without any additional error handling. pub fn try_send(&self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> { send( diff --git a/rs/moq-tokio/src/quic/backend.rs b/rs/moq-tokio/src/quic/backend.rs index 1dbb82af289..58a01c62f00 100644 --- a/rs/moq-tokio/src/quic/backend.rs +++ b/rs/moq-tokio/src/quic/backend.rs @@ -582,6 +582,8 @@ struct Socket { /// Wakes every sender blocked on a full send buffer from the socket's single /// write-readiness registration. blocked: Arc, + /// When a send error was last logged, shared so a busy server logs one per interval. + last_send_error: Arc>>, } impl Socket { @@ -594,6 +596,7 @@ impl Socket { state: Arc::new(state), local, blocked: Default::default(), + last_send_error: Default::default(), }) } @@ -658,12 +661,15 @@ impl driver::UdpSender for Socket { return Poll::Ready(Ok(())); }; loop { - // `send` logs and drops a failed datagram rather than failing the connection, as - // UDP loss would; only `WouldBlock` comes back. - #[allow(deprecated)] - match io.try_io(tokio::io::Interest::WRITABLE, || self.state.send(io.into(), transmit)) { + match io.try_io(tokio::io::Interest::WRITABLE, || { + self.state.try_send(io.into(), transmit) + }) { + Ok(()) => return Poll::Ready(Ok(())), Err(err) if err.kind() == std::io::ErrorKind::WouldBlock => {} - res => return Poll::Ready(res), + Err(err) => { + let mut last = self.last_send_error.lock().unwrap(); + return Poll::Ready(driver::send_failed(&mut last, err, transmit)); + } } // Every connection sends from its own task, but tokio keeps one waker per // direction, so register a fan-out to all of them instead of this task's. @@ -1018,6 +1024,39 @@ mod tests { pinned_connection("[::1]:0", Some("localhost")).await; } + /// The server's socket hands a send that finds no route back to the connection, as the + /// client's does, rather than logging it as loss. Linux refuses a v4-mapped destination on an + /// IPv6-only socket with `ENETUNREACH`, an unroutable family without touching the host's routes. + #[cfg(target_os = "linux")] + #[tokio::test] + async fn server_socket_returns_unreachable_sends() { + let socket = socket2::Socket::new( + socket2::Domain::IPV6, + socket2::Type::DGRAM, + Some(socket2::Protocol::UDP), + ) + .unwrap(); + socket.set_only_v6(true).unwrap(); + socket.set_nonblocking(true).unwrap(); + socket + .bind(&net::SocketAddr::from((net::Ipv6Addr::LOCALHOST, 0)).into()) + .unwrap(); + let socket = Socket::new(socket.into()).unwrap(); + + let transmit = moq_sock::udp::Transmit { + destination: net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.to_ipv6_mapped().into(), 1), + ecn: None, + contents: b"hello", + segment_size: None, + src_ip: None, + }; + let mut sender = driver::AsyncUdpSocket::create_sender(&socket); + let result = std::future::poll_fn(|cx| sender.as_mut().poll_send(&transmit, cx)).await; + + let err = result.expect_err("an unroutable send must reach the connection"); + assert_eq!(err.kind(), std::io::ErrorKind::NetworkUnreachable); + } + async fn pinned_connection(bind: &str, host_name: Option<&str>) { let quic = crate::quic::Config::default(); let config = listen::Config { diff --git a/rs/moq-tokio/src/quic/driver/connection.rs b/rs/moq-tokio/src/quic/driver/connection.rs index 8de19c76139..e5bc65db8d3 100644 --- a/rs/moq-tokio/src/quic/driver/connection.rs +++ b/rs/moq-tokio/src/quic/driver/connection.rs @@ -266,30 +266,12 @@ impl Future for ConnectionDriver { conn.terminate(e, &self.conn.shared); return Poll::Ready(Ok(())); } - let mut keep_going = match conn.drive_transmit(cx) { - Ok(keep_going) => keep_going, - // No route to the peer, so the handshake can never finish: fail it now rather than at - // the handshake timeout, which lets a dial race move on to the next address. The - // driver keeps running until the closed connection drains, so the endpoint forgets it - // even while the application still holds a handle. - Err(e) if moq_sock::udp::is_unreachable_err(&e) => { - if !conn.inner.is_closed() { - // Closed, so dropping the last handle cannot overwrite the cause. - conn.inner.close(Instant::now(), 0u32.into(), Bytes::new()); - let cause = - TransportError::new(TransportErrorCode::NO_VIABLE_PATH, e.to_string()); - conn.terminate(cause.into(), &self.conn.shared); - } - true - } - Err(e) => { - // Transmit failed, so close the connection and clean state before returning the error. - if !conn.inner.is_closed() { - conn.implicit_close(&self.conn.shared); - } - return Poll::Ready(Err(e)); + let mut keep_going = conn.drive_transmit(cx).inspect_err(|_| { + // Transmit failed, so close the connection and clean state before returning the error. + if !conn.inner.is_closed() { + conn.implicit_close(&self.conn.shared); } - }; + })?; // If a timer expires, there might be more to transmit. When we transmit something, we // might need to reset a timer. Hence, we must loop until neither happens. keep_going |= conn.drive_timer(cx); @@ -1144,12 +1126,10 @@ impl State { self.buffered_transmit = Some(t); return Ok(false); } - // An established connection outlives a route that drops for a moment, such as a - // client switching networks, so the datagram is just lost. - Poll::Ready(Err(e)) - if moq_sock::udp::is_unreachable_err(&e) && !self.inner.is_handshaking() => - { - tracing::debug!(%e, "transmit failed; treating it as loss"); + // The datagram is lost, and moq-quic decides whether the connection survives it. + Poll::Ready(Err(e)) if moq_sock::udp::is_unreachable_err(&e) => { + tracing::debug!(%e, "no route to the peer"); + self.inner.handle_unreachable(); } Poll::Ready(Err(e)) => return Err(e), Poll::Ready(Ok(())) => {} diff --git a/rs/moq-tokio/src/quic/driver/mod.rs b/rs/moq-tokio/src/quic/driver/mod.rs index a20c51650ff..38e5588f6ed 100644 --- a/rs/moq-tokio/src/quic/driver/mod.rs +++ b/rs/moq-tokio/src/quic/driver/mod.rs @@ -76,6 +76,7 @@ pub use crate::quic::driver::incoming::{Incoming, IncomingFuture, RetryError}; pub use crate::quic::driver::recv_stream::{ Credit, ReadError, ReadExactError, ReadToEndError, RecvStream, ResetError, }; +pub(crate) use crate::quic::driver::runtime::send_failed; #[cfg(test)] pub(crate) use crate::quic::driver::runtime::wrap_udp_socket; pub use crate::quic::driver::runtime::{AsyncUdpSocket, UdpSender}; diff --git a/rs/moq-tokio/src/quic/driver/runtime/mod.rs b/rs/moq-tokio/src/quic/driver/runtime/mod.rs index 3f806a98367..c139013f5b8 100644 --- a/rs/moq-tokio/src/quic/driver/runtime/mod.rs +++ b/rs/moq-tokio/src/quic/driver/runtime/mod.rs @@ -67,9 +67,8 @@ pub trait UdpSender: Send + Sync + Debug + 'static { /// A single [`UdpSender`] will be re-used, even if `poll_send` returns `Poll::Ready` once, /// unlike [`Future::poll`], so calling it again after readiness should not panic. /// - /// An error matching [`moq_sock::udp::is_unreachable_err`] fails a handshaking connection - /// with `NO_VIABLE_PATH` and counts as loss once it is established; any other error closes - /// the connection. + /// An error matching [`moq_sock::udp::is_unreachable_err`] reaches + /// [`moq_quic::Connection::handle_unreachable`]; any other error closes the connection. fn poll_send( self: Pin<&mut Self>, transmit: &Transmit<'_>, @@ -166,13 +165,7 @@ where // registers us for a wakeup, or the send succeeds if this really was just a // transient failure. Err(e) if e.kind() == io::ErrorKind::WouldBlock => continue, - // No route to the destination: retransmitting cannot help, so the connection - // decides whether to give up on the peer. - Err(e) if moq_sock::udp::is_unreachable_err(&e) => return Poll::Ready(Err(e)), - Err(e) => { - log_sendmsg_error(this.last_send_error, &e, transmit); - return Poll::Ready(Ok(())); - } + Err(e) => return Poll::Ready(send_failed(this.last_send_error, e, transmit)), Ok(()) => return Poll::Ready(Ok(())), } } @@ -186,22 +179,30 @@ where /// Limits I/O error logging to one message per minute. const IO_ERROR_LOG_INTERVAL: Duration = Duration::from_secs(60); -fn log_sendmsg_error( +/// What a failed send, other than `WouldBlock`, means for [`UdpSender::poll_send`] +/// +/// No route to the destination comes back, since retransmitting cannot help and the connection +/// decides whether to give up on the peer. Anything else is logged at most once per +/// [`IO_ERROR_LOG_INTERVAL`] and treated as loss, which UDP always allows. +pub(crate) fn send_failed( last_send_error: &mut Option, - error: &io::Error, + error: io::Error, transmit: &Transmit<'_>, -) { +) -> io::Result<()> { + if moq_sock::udp::is_unreachable_err(&error) { + return Err(error); + } #[cfg(unix)] // Unix `EMSGSIZE` is expected for MTU probes. - if moq_sock::udp::is_msg_size_err(error) { - return; + if moq_sock::udp::is_msg_size_err(&error) { + return Ok(()); } let now = Instant::now(); if last_send_error .is_some_and(|last| now.saturating_duration_since(last) <= IO_ERROR_LOG_INTERVAL) { - return; + return Ok(()); } *last_send_error = Some(now); @@ -214,6 +215,7 @@ fn log_sendmsg_error( transmit.contents.len(), transmit.segment_size ); + Ok(()) } /// Parts of the [`UdpSender`] trait that aren't asynchronous or require storing wakers. diff --git a/rs/moq-uring/src/quic/driver/connection.rs b/rs/moq-uring/src/quic/driver/connection.rs index 3f8f063eaae..3ece4e59b30 100644 --- a/rs/moq-uring/src/quic/driver/connection.rs +++ b/rs/moq-uring/src/quic/driver/connection.rs @@ -168,18 +168,6 @@ impl Inner { state.fail(err); } - /// Fail the connection because its peer has no route, closing it so the - /// driver still drains it out of the endpoint. - pub(crate) fn unreachable(&self, err: &std::io::Error) { - self.conn - .borrow_mut() - .close(moq_clock::Instant::now(), 0u32.into(), Bytes::new()); - self.state.borrow_mut().fail(Error::Transport { - code: moq_quic::TransportErrorCode::NO_VIABLE_PATH.into(), - reason: err.to_string(), - }); - } - /// Park `waiter` until stream `id` is writable again. pub(crate) fn park_writable(&self, id: StreamId, waiter: &kio::Waiter) { let mut state = self.state.borrow_mut(); diff --git a/rs/moq-uring/src/quic/driver/endpoint.rs b/rs/moq-uring/src/quic/driver/endpoint.rs index 1b45c53b313..9f0504b6942 100644 --- a/rs/moq-uring/src/quic/driver/endpoint.rs +++ b/rs/moq-uring/src/quic/driver/endpoint.rs @@ -462,23 +462,23 @@ impl Inner { self.task_waiters.borrow_mut().wake(); } - /// A send to `addr` found no route, so a handshake dialing it can never - /// finish: fail it now rather than at the handshake timeout. An established - /// connection rides it out as loss, since a route that drops for a moment - /// (a client switching networks) comes back. + /// A send to `addr` found no route: tell every connection to that peer, + /// and moq-quic decides which of them give up. fn unreachable(&self, addr: SocketAddr, err: &std::io::Error) { + tracing::debug!(%addr, %err, "no route to the peer"); let conns: Vec = { let all = self.conns.borrow(); self.peers .borrow() .range((addr, ConnectionHandle(0))..=(addr, ConnectionHandle(usize::MAX))) .filter_map(|(_, key)| all.get(key)) - .filter(|shared| shared.conn.borrow().is_handshaking()) .cloned() .collect() }; for conn in conns { - conn.unreachable(err); + conn.conn.borrow_mut().handle_unreachable(); + // The driver reports a failed handshake and drains it out of the table. + conn.kick(); } }