Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m1/quic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ cache limits remain separate; bitrate pacing composes with this memory cap.
and MAX_DATA are raised after SETUP identifies a cluster peer
- [Shard the endpoint](/quest/m1/quic/shard.md) - the library shards a
server endpoint across cores by default, replacing the `--workers` group
- [Surface UDP send errors](/quest/m1/quic/send-errors.md) - a client drops a QUIC attempt the moment its address family is unreachable

## Related

Expand Down
25 changes: 0 additions & 25 deletions quest/m1/quic/send-errors.md

This file was deleted.

1 change: 1 addition & 0 deletions rs/moq-quic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +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).
- 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.
Expand Down
41 changes: 41 additions & 0 deletions rs/moq-sock/src/udp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,26 @@ pub fn is_msg_size_err(err: &io::Error) -> bool {
}
}

/// Returns true if the given send error means the local stack has no way to reach the destination
///
/// Most send errors are transient, so higher layers treat them as packet loss. These are not:
/// there is no route to the address (ENETUNREACH, EHOSTUNREACH) or the interface is down
/// (ENETDOWN), and the Windows `WSAE*` equivalents. Retransmitting cannot fix them, so a
/// connection attempt can give up on that address at once, for example to dial the other address
/// family.
///
/// They are only local for an unconnected socket with transport errors left disabled, as
/// `UdpSocketState` sockets are by default. A `connect`ed socket, or one with `IP_RECVERR`, can
/// report a received ICMP error here instead, which an off-path attacker can forge.
pub fn is_unreachable_err(err: &io::Error) -> bool {
matches!(
err.kind(),
io::ErrorKind::NetworkUnreachable
| io::ErrorKind::HostUnreachable
| io::ErrorKind::NetworkDown
)
}

/// Log at most 1 IO error per minute
#[cfg(not(wasm_browser))]
const IO_ERROR_LOG_INTERVAL: Duration = Duration::from_secs(60);
Expand Down Expand Up @@ -357,6 +377,27 @@ mod tests {

use super::*;

#[cfg(unix)]
#[test]
fn unreachable_errors_are_only_the_routing_failures() {
for code in [libc::ENETUNREACH, libc::EHOSTUNREACH, libc::ENETDOWN] {
let err = io::Error::from_raw_os_error(code);
assert!(is_unreachable_err(&err), "{err}");
}
// Loss, readiness, MTU probes, the GSO fallback, and ICMP noise all stay retryable.
for code in [
libc::ENOBUFS,
libc::EAGAIN,
libc::EMSGSIZE,
libc::EINVAL,
libc::EIO,
libc::ECONNREFUSED,
] {
let err = io::Error::from_raw_os_error(code);
assert!(!is_unreachable_err(&err), "{err}");
}
}

#[test]
fn effective_segment_size() {
assert_eq!(
Expand Down
35 changes: 30 additions & 5 deletions rs/moq-tokio/src/quic/driver/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,30 @@ impl Future for ConnectionDriver {
conn.terminate(e, &self.conn.shared);
return Poll::Ready(Ok(()));
}
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);
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));
}
})?;
};
// 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);
Expand Down Expand Up @@ -1176,6 +1194,13 @@ 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");
}
Poll::Ready(Err(e)) => return Err(e),
Poll::Ready(Ok(())) => {}
}
Expand Down
51 changes: 40 additions & 11 deletions rs/moq-tokio/src/quic/driver/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ 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.
fn poll_send(
self: Pin<&mut Self>,
transmit: &Transmit<'_>,
Expand Down Expand Up @@ -162,6 +166,9 @@ 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(()));
Expand Down Expand Up @@ -235,28 +242,50 @@ mod tests {

#[test]
fn non_would_block_send_errors_are_logged_and_ignored() {
let mut sender = Box::pin(UdpSenderHelper::new(TestSocket, writable));
let transmit = Transmit {
destination: SocketAddr::from(([127, 0, 0, 1], 4433)),
ecn: None,
contents: &[],
segment_size: None,
src_ip: None,
};
let mut sender = Box::pin(UdpSenderHelper::new(
TestSocket(io::ErrorKind::PermissionDenied),
writable,
));
let mut cx = Context::from_waker(Waker::noop());

let result = sender.as_mut().poll_send(&transmit, &mut cx);
let result = sender.as_mut().poll_send(&transmit(), &mut cx);

assert!(matches!(result, Poll::Ready(Ok(()))));
assert!(sender.last_send_error.is_some());
}

#[test]
fn unreachable_send_errors_are_returned() {
let mut sender = Box::pin(UdpSenderHelper::new(
TestSocket(io::ErrorKind::NetworkUnreachable),
writable,
));
let mut cx = Context::from_waker(Waker::noop());

let result = sender.as_mut().poll_send(&transmit(), &mut cx);

assert!(
matches!(result, Poll::Ready(Err(ref e)) if e.kind() == io::ErrorKind::NetworkUnreachable),
"{result:?}"
);
}

fn transmit() -> Transmit<'static> {
Transmit {
destination: SocketAddr::from(([127, 0, 0, 1], 4433)),
ecn: None,
contents: &[],
segment_size: None,
src_ip: None,
}
}

#[derive(Debug)]
struct TestSocket;
struct TestSocket(io::ErrorKind);

impl UdpSenderHelperSocket for TestSocket {
fn try_send(&self, _transmit: &Transmit<'_>) -> io::Result<()> {
Err(io::ErrorKind::PermissionDenied.into())
Err(self.0.into())
}

fn max_transmit_segments(&self) -> usize {
Expand Down
Loading
Loading