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
43 changes: 20 additions & 23 deletions dart/moq_ffi/lib/src/moq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7195,7 +7195,6 @@ enum MoqProtocolKind {
timeout,
version,
deliveryTimeout,
sessionClosed,
goingAway,
tooFarBehind,
malformedTrack,
Expand Down Expand Up @@ -7242,48 +7241,46 @@ class FfiConverterMoqProtocolKind {
case 9:
return LiftRetVal(MoqProtocolKind.deliveryTimeout, 4);
case 10:
return LiftRetVal(MoqProtocolKind.sessionClosed, 4);
case 11:
return LiftRetVal(MoqProtocolKind.goingAway, 4);
case 12:
case 11:
return LiftRetVal(MoqProtocolKind.tooFarBehind, 4);
case 13:
case 12:
return LiftRetVal(MoqProtocolKind.malformedTrack, 4);
case 14:
case 13:
return LiftRetVal(MoqProtocolKind.notFound, 4);
case 15:
case 14:
return LiftRetVal(MoqProtocolKind.unroutable, 4);
case 16:
case 15:
return LiftRetVal(MoqProtocolKind.old, 4);
case 17:
case 16:
return LiftRetVal(MoqProtocolKind.evicted, 4);
case 18:
case 17:
return LiftRetVal(MoqProtocolKind.wrongSize, 4);
case 19:
case 18:
return LiftRetVal(MoqProtocolKind.frameTooLarge, 4);
case 20:
case 19:
return LiftRetVal(MoqProtocolKind.timestampMismatch, 4);
case 21:
case 20:
return LiftRetVal(MoqProtocolKind.app, 4);
case 22:
case 21:
return LiftRetVal(MoqProtocolKind.unknown, 4);
case 23:
case 22:
return LiftRetVal(MoqProtocolKind.tooManyRequests, 4);
case 24:
case 23:
return LiftRetVal(MoqProtocolKind.expired, 4);
case 25:
case 24:
return LiftRetVal(MoqProtocolKind.authTokenCacheOverflow, 4);
case 26:
case 25:
return LiftRetVal(MoqProtocolKind.malformedAuthToken, 4);
case 27:
case 26:
return LiftRetVal(MoqProtocolKind.unknownAuthTokenAlias, 4);
case 28:
case 27:
return LiftRetVal(MoqProtocolKind.invalidRequestId, 4);
case 29:
case 28:
return LiftRetVal(MoqProtocolKind.invalidPath, 4);
case 30:
case 29:
return LiftRetVal(MoqProtocolKind.invalidAuthority, 4);
case 31:
case 30:
return LiftRetVal(MoqProtocolKind.tooManyRequestUpdates, 4);
default:
throw UniffiInternalError(
Expand Down
2 changes: 0 additions & 2 deletions go/wrapper/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ const (
ProtocolKindVersion = ffi.MoqProtocolKindVersion
// ProtocolKindDeliveryTimeout identifies delivery timeout.
ProtocolKindDeliveryTimeout = ffi.MoqProtocolKindDeliveryTimeout
// ProtocolKindSessionClosed identifies session closed.
ProtocolKindSessionClosed = ffi.MoqProtocolKindSessionClosed
// ProtocolKindGoingAway identifies going away.
ProtocolKindGoingAway = ffi.MoqProtocolKindGoingAway
// ProtocolKindTooFarBehind identifies too far behind.
Expand Down
4 changes: 0 additions & 4 deletions quest/m2/api-shape/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,3 @@ search misses or which are not items:
`just rs macos-test` enables, and its WASI arm (`udp/wasi.rs`), which no
target builds. Update [cmsg length on send](/quest/m3/cmsg-len-send.md),
which names the feature.

## Required

- [A peer's closed session reads as Closed in the bindings](/quest/m2/api-shape/session-closed.md) - a remote SESSION_CLOSED maps to `MoqError::Closed`, as a local close does
44 changes: 0 additions & 44 deletions quest/m2/api-shape/session-closed.md

This file was deleted.

41 changes: 24 additions & 17 deletions rs/moq-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pub enum MoqProtocolKind {
Version,
/// The content missed its delivery deadline.
DeliveryTimeout,
/// The session ended, taking this stream with it.
SessionClosed,
/// The session is going away (a GOAWAY was received).
GoingAway,
/// The reader fell too far behind and content was dropped to catch up.
Expand Down Expand Up @@ -156,7 +154,6 @@ fn session_kind(err: &moq_net::SessionError) -> MoqProtocolKind {

fn stream_kind(err: &moq_net::StreamError) -> MoqProtocolKind {
match err {
moq_net::StreamError::Session(_) => MoqProtocolKind::SessionClosed,
moq_net::StreamError::Internal => MoqProtocolKind::Internal,
moq_net::StreamError::Cancel => MoqProtocolKind::Cancel,
moq_net::StreamError::DeliveryTimeout => MoqProtocolKind::DeliveryTimeout,
Expand Down Expand Up @@ -280,7 +277,7 @@ pub enum MoqError {
#[error("cancelled")]
Cancelled,

/// The handle or connection is closed.
/// The handle or connection is closed, or the session behind it ended, here or at a peer.
#[error("closed")]
Closed,

Expand Down Expand Up @@ -425,11 +422,12 @@ impl From<moq_net::Error> for MoqError {
reason: "transport idle timeout".into(),
},
moq_net::Error::NotFound => Self::NotFound,
// A track whose own session closed aborts its open groups with this; a remote
// SESSION_CLOSED decodes as `Internal`, so only the local close lands here.
// The session behind a track or group ended, here or at a peer: a clean session
// close, or a SESSION_CLOSED reset, which carries no reason to report.
moq_net::Error::Closed
| moq_net::Error::GoingAway
| moq_net::Error::Stream(moq_net::StreamError::Session(moq_net::SessionError::Cancel)) => Self::Closed,
| moq_net::Error::Session(moq_net::SessionError::Cancel)
| moq_net::Error::Stream(moq_net::StreamError::Session(_)) => Self::Closed,
moq_net::Error::Cancel => Self::Cancelled,
moq_net::Error::Unauthorized => Self::Unauthorized,
moq_net::Error::Expired => Self::Expired,
Expand Down Expand Up @@ -624,7 +622,8 @@ mod tests {

#[test]
fn received_known_codes_keep_their_registry() {
for code in [0, 1, 2, 3, 6, 0x10, 0x11, 0x15, 0x20, 468, u32::MAX] {
// A clean session close and SESSION_CLOSED read as `Closed` instead.
for code in [1, 2, 3, 6, 0x10, 0x11, 0x15, 0x20, 468, u32::MAX] {
let MoqError::Protocol { details } =
MoqError::from(moq_net::Error::from(moq_net::SessionError::from_code(code)))
else {
Expand All @@ -633,7 +632,7 @@ mod tests {
assert_eq!(details.scope, MoqErrorScope::Session);
assert_eq!(details.code, code);
}
for code in [0, 1, 2, 3, 4, 5, 0x12, 0x20, 468, u32::MAX] {
for code in [0, 1, 2, 4, 5, 0x12, 0x20, 468, u32::MAX] {
let MoqError::Protocol { details } =
MoqError::from(moq_net::Error::from(moq_net::StreamError::from_code(code)))
else {
Expand Down Expand Up @@ -753,17 +752,25 @@ mod tests {
}
}

/// A group cut by its own session closing is a shutdown; one reset by a peer is not.
/// A session ending reads as a shutdown whichever side closed it, while a session that
/// failed keeps its reason.
#[test]
fn local_session_close_is_closed() {
let local = moq_net::StreamError::Session(moq_net::SessionError::Cancel);
assert!(matches!(MoqError::from(moq_net::Error::from(local)), MoqError::Closed));
fn a_closed_session_is_closed_on_either_side() {
for ended in [
moq_net::Error::from(moq_net::StreamError::Session(moq_net::SessionError::Cancel)),
moq_net::Error::from(moq_net::StreamError::from_code(0x3)),
moq_net::Error::from(moq_net::SessionError::Cancel),
moq_net::Error::from(moq_net::SessionError::from_code(0x0)),
] {
assert!(matches!(MoqError::from(ended.clone()), MoqError::Closed), "{ended:?}");
}

let received = moq_net::StreamError::from_code(0x3);
let MoqError::Protocol { details } = MoqError::from(moq_net::Error::from(received)) else {
panic!("a peer's SESSION_CLOSED lost its code");
let failed = moq_net::Error::from(moq_net::SessionError::Unauthorized);
let MoqError::Protocol { details } = MoqError::from(failed) else {
panic!("a failed session lost its code");
};
assert_eq!(details.kind, MoqProtocolKind::SessionClosed);
assert_eq!(details.scope, MoqErrorScope::Session);
assert_eq!(details.kind, MoqProtocolKind::Unauthorized);
}

#[test]
Expand Down
36 changes: 31 additions & 5 deletions rs/moq-ffi/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8349,8 +8349,8 @@ async fn data_track_names_cannot_collide() {
first.finish().unwrap();
}

/// In-memory sessions whose protocol and origin drivers use the paused test clock.
async fn memory_shutdown_pair() -> (Arc<MoqSession>, Arc<MoqSession>) {
/// In-memory sessions on `version` whose protocol and origin drivers use the paused test clock.
async fn memory_pair(version: &str) -> (Arc<MoqSession>, Arc<MoqSession>) {
fn origin() -> crate::origin::Origin {
let mut config = moq_net::origin::Config::default();
config.pool = moq_net::cache::Pool::unbounded();
Expand All @@ -8363,7 +8363,7 @@ async fn memory_shutdown_pair() -> (Arc<MoqSession>, Arc<MoqSession>) {
}
let a = origin();
let b = origin();
let version: moq_net::Version = "moq-lite-07-wip".parse().unwrap();
let version: moq_net::Version = version.parse().unwrap();
let mut transport = moq_net::transport::memory::Config::default();
transport.protocol = Some(version.alpn().into());
transport.stream_buffer = 1024;
Expand Down Expand Up @@ -8395,7 +8395,7 @@ async fn memory_shutdown_pair() -> (Arc<MoqSession>, Arc<MoqSession>) {

#[tokio::test(start_paused = true)]
async fn shutdown_without_waiter_survives_session_disposal() {
let (publisher, subscriber) = memory_shutdown_pair().await;
let (publisher, subscriber) = memory_pair("moq-lite-07-wip").await;
let broadcast = create_announced(&publisher.publish(), "tail");
let track = broadcast.publish_track("data".into(), Some(timed_info())).unwrap();
let remote = await_announced(&subscriber.consume(), "tail").await;
Expand All @@ -8421,7 +8421,7 @@ async fn shutdown_without_waiter_survives_session_disposal() {

#[tokio::test(start_paused = true)]
async fn shutdown_failure_survives_a_discarded_waiter() {
let (publisher, subscriber) = memory_shutdown_pair().await;
let (publisher, subscriber) = memory_pair("moq-lite-07-wip").await;
let broadcast = create_announced(&publisher.publish(), "live");
let track = broadcast.publish_track("data".into(), Some(timed_info())).unwrap();
let remote = await_announced(&subscriber.consume(), "live").await;
Expand All @@ -8444,6 +8444,32 @@ async fn shutdown_failure_survives_a_discarded_waiter() {
subscriber.cancel(0);
}

/// A track's reader sees `Closed` when the session under it closes, whichever side closed it.
#[tokio::test(start_paused = true)]
async fn a_closed_session_ends_its_tracks_as_closed() {
for version in ["moq-lite-07-wip", "moq-transport-18"] {
for publisher_closes in [false, true] {
let (publisher, subscriber) = memory_pair(version).await;
let broadcast = create_announced(&publisher.publish(), "live");
let track = broadcast.publish_track("data".into(), Some(timed_info())).unwrap();
let remote = await_announced(&subscriber.consume(), "live").await;
let reader = remote.subscribe_track("data".into(), None).await.unwrap();
shutdown_ready(&track, &reader).await;
match publisher_closes {
true => publisher.cancel(0),
false => subscriber.cancel(0),
}
let Err(error) = reader.read_frame().await else {
panic!("{version}: the track outlived its session");
};
assert!(
matches!(error, MoqError::Closed),
"{version}, publisher_closes={publisher_closes}: {error:?}"
);
}
}
}

/// Real sockets exercise the FFI runtime and both accepted/client session handles.
async fn shutdown_pair() -> (Arc<MoqServer>, Arc<MoqSession>, Arc<MoqSession>) {
session_pair("moq-lite-07-wip").await
Expand Down
9 changes: 6 additions & 3 deletions rs/moq-net/tests/integration/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::time::Duration;
use bytes::Bytes;
use moq_net::broadcast::TracksEvent;
use moq_net::socket::{Endpoint, TcpStream, TrackStream};
use moq_net::{Error, Version, frame, group, origin, track};
use moq_net::{Error, StreamError, Version, frame, group, origin, track};

use crate::support::harness::{MockConnectOptions, MockPair, connect_mock, spawn};

Expand Down Expand Up @@ -807,9 +807,12 @@ async fn closing_an_endpoint_ends_its_sessions() {
let (track_dialed, track_accepted) = connect_track(&alice, &bob).await;

bob.close();
// Through the relay, bob's close reaches alice as a SESSION_CLOSED reset, as it would
// on one origin.
let ended = read(&mut tcp_dialed.consumer).await;
assert!(
read(&mut tcp_dialed.consumer).await.is_err(),
"bob's tcp half outlived his endpoint"
matches!(ended, Err(Error::Stream(StreamError::Session(_)))),
"bob's tcp half outlived his endpoint: {ended:?}"
);
// Both halves of bob's own tcp session end.
assert!(read(&mut tcp_accepted.consumer).await.is_err());
Expand Down
Loading