From 6637721bf4fc7ff81afa0a46826778c75b35349d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 1 Nov 2026 03:10:36 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m2/cmsg-windows-truncation.md Quest-Claim: c51c97019d7643dc From be7fc31fac79c72dc88b189c294f42fb89253d1b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 1 Nov 2026 03:14:04 -0800 Subject: [PATCH 2/3] fix(sock): notice truncated control data on Windows receives WSARecvMsg reports MSG_CTRUNC in WSAMSG.dwFlags. Keep the datagram with whatever metadata fit and warn once, matching the Unix receive paths from #7394. The 128-byte buffer already fits what Windows sends, so this is defensive. Co-Authored-By: Claude Opus 5.5 --- quest/m2/README.md | 1 - quest/m2/cmsg-windows-truncation.md | 13 ------------- rs/moq-sock/src/udp/windows.rs | 16 ++++++++++++++-- 3 files changed, 14 insertions(+), 16 deletions(-) delete mode 100644 quest/m2/cmsg-windows-truncation.md diff --git a/quest/m2/README.md b/quest/m2/README.md index 282d0975da8..a9d7287003f 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -240,7 +240,6 @@ lite-07; bitrate enforcement is not part of this release. - [PUBLISH_DONE says why](/quest/m2/publish-done-codes.md) - GOING_AWAY, TOO_FAR_BEHIND, and EXPIRED round-trip as stream codes - [An interrupted mp4 recording keeps its last fragment](/quest/m2/mp4-sigint-flush.md) - SIGINT flushes the buffering fragment before finishing - [Repair a crashed mp4 recording](/quest/m2/mp4-repair.md) - a crashed recording's fragmented file becomes a regular MP4 -- [Windows receives notice truncated control data](/quest/m2/cmsg-windows-truncation.md) - Windows handles `MSG_CTRUNC` like the Unix 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 - [An ended HLS playlist has no trailing gap](/quest/m2/hls-trailing-gap.md) - no zero-duration `EXT-X-GAP` before `EXT-X-ENDLIST` 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..5e2ddc556ab 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 @@ -203,6 +206,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; From bb538bb41121eace8caf8a899ae0fc1d1c827256 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 1 Nov 2026 03:16:49 -0800 Subject: [PATCH 3/3] fix(sock): keep Windows datagrams whose control data Winsock truncated Winsock fails WSARecvMsg with WSAEMSGSIZE when control data is truncated, so the MSG_CTRUNC check never ran. Treat WSAEMSGSIZE with MSG_CTRUNC and without MSG_TRUNC as a received datagram. Co-Authored-By: Claude Opus 5.5 --- rs/moq-sock/src/udp/windows.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/rs/moq-sock/src/udp/windows.rs b/rs/moq-sock/src/udp/windows.rs index 5e2ddc556ab..505b6edbab8 100644 --- a/rs/moq-sock/src/udp/windows.rs +++ b/rs/moq-sock/src/udp/windows.rs @@ -184,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); } }