diff --git a/quest/m2/README.md b/quest/m2/README.md index fd1acc4fc4b..699daf5c59a 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -235,7 +235,6 @@ lite-07; bitrate enforcement is not part of this release. - [Certificate reload and qmux's tasks are supervised](/quest/m2/tls-reload-supervision.md) - a panic in either fails loudly instead of silently stopping - [PUBLISH_DONE says why](/quest/m2/publish-done-codes.md) - GOING_AWAY, TOO_FAR_BEHIND, and EXPIRED round-trip as stream codes - [moq repair refuses a live recording](/quest/m2/mp4-repair-lock.md) - the recorder's advisory lock keeps `moq repair mp4` off a file still being written -- [Windows receives notice truncated control data](/quest/m2/cmsg-windows-truncation.md) - Windows handles `MSG_CTRUNC` like the Unix paths - [The error-queue reader decodes truncated control data](/quest/m2/errqueue-truncation.md) - `MSG_ERRQUEUE` keeps what fit on `MSG_CTRUNC`, like the receive paths - [moq-quic's internal dev-dependencies are path-only](/quest/m2/quic-dev-dep-path.md) - moq-congestion is a path dev-dependency - [moq-mux's AAC config reports SBR](/quest/m2/aac-sbr-config.md) - moq-audio reads backward-compatible SBR from the config diff --git a/quest/m2/cmsg-windows-truncation.md b/quest/m2/cmsg-windows-truncation.md deleted file mode 100644 index 46b012e3863..00000000000 --- a/quest/m2/cmsg-windows-truncation.md +++ /dev/null @@ -1,13 +0,0 @@ -# [XS] Windows receives notice truncated control data - -## Goal - -moq-sock's Windows receive path detects truncated control data (`MSG_CTRUNC`) and keeps the packet with whatever metadata fit, logging once, as the Unix paths do. - -## Plan - -Follow-up of [moq-dev/moq#7394](https://github.com/moq-dev/moq/pull/7394), which did this for `recvmmsg`, `recvmsg`, and Apple's `recvmsg_x`. Windows's 128-byte buffer already fits what it uses, so this is defensive. - -Decided 2026-10-30 (maintainer, follow-up planning after the /quest-afk run). Match #7394's handling; verify with a cross-target `cargo check` and the platform workflow, since no Windows host runs locally. - -Public API: none. Wire: none. diff --git a/rs/moq-sock/src/udp/windows.rs b/rs/moq-sock/src/udp/windows.rs index f6b284b25db..505b6edbab8 100644 --- a/rs/moq-sock/src/udp/windows.rs +++ b/rs/moq-sock/src/udp/windows.rs @@ -4,7 +4,10 @@ use std::{ net::{IpAddr, Ipv4Addr}, os::windows::io::AsRawSocket, ptr, - sync::atomic::{AtomicUsize, Ordering}, + sync::{ + Once, + atomic::{AtomicUsize, Ordering}, + }, }; use libc::{c_int, c_uint}; @@ -13,7 +16,7 @@ use windows_sys::Win32::Networking::WinSock; use crate::udp::{ EcnCodepoint, RecvMeta, Transmit, UdpSockRef, cmsg::{self, CMsgHdr}, - log::debug, + log::{debug, warn}, }; /// QUIC-friendly UDP socket for Windows @@ -181,16 +184,24 @@ impl UdpSocketState { }; let mut len = 0; - unsafe { - let rc = (self.wsa_recvmsg)( + let rc = unsafe { + (self.wsa_recvmsg)( socket.0.as_raw_socket() as usize, &mut wsa_msg, &mut len, ptr::null_mut(), None, - ); - if rc == -1 { - return Err(io::Error::last_os_error()); + ) + }; + if rc == -1 { + let err = io::Error::last_os_error(); + // Winsock fails the call with `WSAEMSGSIZE` when either the payload or the control data + // was truncated, and sets `MSG_TRUNC` / `MSG_CTRUNC` to say which. Only truncated + // control data is recoverable: the whole datagram arrived, so keep it below. + // https://learn.microsoft.com/en-us/windows/win32/api/ws2def/ns-ws2def-wsamsg#remarks + let truncated = wsa_msg.dwFlags & (WinSock::MSG_TRUNC | WinSock::MSG_CTRUNC); + if err.raw_os_error() != Some(WinSock::WSAEMSGSIZE) || truncated != WinSock::MSG_CTRUNC { + return Err(err); } } @@ -203,6 +214,15 @@ impl UdpSocketState { addr.as_socket() }; + // `MSG_CTRUNC` keeps the datagram with the metadata that fit: losing metadata beats losing + // the packet. The iterator below stays within the `Control.len` Winsock returned. + if wsa_msg.dwFlags & WinSock::MSG_CTRUNC != 0 { + static CTRUNC: Once = Once::new(); + CTRUNC.call_once(|| { + warn!("control messages truncated to {CMSG_LEN} bytes; some receive metadata is lost"); + }); + } + // Decode control messages (PKTINFO and ECN) let mut ecn_bits = 0; let mut dst_ip = None;