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
3 changes: 2 additions & 1 deletion quest/m1/transport-upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ Shared decisions:

## Required

- [Rust edge cases](/quest/m1/transport-upgrade/polish.md) - no false GOAWAY warning on upgrade, and a failed WebSocket handshake falls back to the pending QUIC dial
- [JavaScript](/quest/m1/transport-upgrade/js.md) - js/net keeps the WebTransport dial after WebSocket wins and migrates through the client-goaway handover
- [Closed fallback](/quest/m1/transport-upgrade/closed-fallback.md) - a WebSocket session that closes right after connecting falls back to the pending QUIC dial instead of redialing
- [JS qmux finish](/quest/m1/transport-upgrade/js-qmux-finish.md) - `@moq/qmux` reports a cleanly finished send stream as closed without error
Comment on lines +62 to +63

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Consume the qmux fix before completing the quest

Removing the Rust edge-case quest leaves its GOAWAY-warning goal unresolved: the reviewed tree still pins qmux = 0.5.1 in Cargo.toml, while the commit description states that the clean-finish fix will only arrive with qmux 0.6. Consequently every WebSocket-to-QUIC upgrade can still emit the false failed to send goaway warning from rs/moq-net/src/lite/session.rs; keep this quest open or include the dependency update and regression coverage.

AGENTS.md reference: AGENTS.md:L16-L18

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. qmux 0.6.0 is not published yet (moq-dev/web-transport#402 is still open), so this PR is blocked on that release and will not merge until the qmux bump lands here.

(Written by Claude Opus 5.5)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: qmux 0.6.1 (with web-transport#399, #401, #402) arrived through a dev merge into the questline (c57de66), and websocket_upgrades_to_quic now asserts failed to send goaway never logs (20 of 20 runs clean).

(Written by Claude Opus 5.5)


## Related

Expand Down
30 changes: 30 additions & 0 deletions quest/m1/transport-upgrade/closed-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# [S] Fall back to QUIC when the WebSocket session closes at once

## Goal

When WebSocket wins the dial race and its session closes right after
connecting, the `Connection` moves onto the QUIC dial that is still pending
instead of dropping it and redialing. On moq-lite and IETF draft 17+ the
client handshake does not wait for the server, so a server refusing the
WebSocket session looks like this rather than like a handshake failure, which
already falls back.

## Plan

- Today `run_session` in `moq-tokio`'s `connection.rs` returns when the
WebSocket session closes, and the pending upgrade is dropped. The redial
starts a fresh QUIC dial and has lost QUIC's head start.
- Decide what counts as "at once". The unhealthy-session threshold that
already feeds the backoff may be the right line. Keep the connect deadline
that bounds the pending dial as the only deadline.
- An auth close on the WebSocket session is probably still terminal, the way
it is for a lone session. Check how the race treats a mixed auth pair and
match it.
- Test with the held-QUIC forwarder in the connection tests, as the handshake
fallback test does, with a default moq-lite client.

Public API: none. Wire: none.

## Related

- [#4296](https://github.com/moq-dev/moq/pull/4296) - the handshake-failure fallback this extends
22 changes: 22 additions & 0 deletions quest/m1/transport-upgrade/js-qmux-finish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# [XS] Clean finish in @moq/qmux

## Goal

`@moq/qmux` reports a send stream that finished cleanly as closed without
error, so `@moq/net` does not treat a delivered GOAWAY or SETUP as a failure
over the WebSocket fallback.

## Plan

The Rust qmux crate reported every finished stream as `connection closed`
(fixed in moq-dev/web-transport#402). Check whether the TypeScript peer in
`moq-dev/web-transport` (`js/qmux`) has the same bug, and whether `@moq/net`
waits on a finished writable anywhere it would notice. If it does, fix it
there with a regression test, release, and bump `@moq/qmux` in `js/net`. If
not, note that in the PR that deletes this quest.

Public API: none. Wire: none.

## Related

- [JavaScript upgrade](/quest/m1/transport-upgrade/js.md) - sends a GOAWAY over the WebSocket session on every upgrade
24 changes: 0 additions & 24 deletions quest/m1/transport-upgrade/polish.md

This file was deleted.

114 changes: 90 additions & 24 deletions rs/moq-tokio/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ impl Client {
/// Race the QUIC dial against the WebSocket fallback, handshaking whichever wins.
///
/// When WebSocket wins while QUIC is still dialing, the QUIC dial carries on as
/// [`Dialed::upgrade`] rather than being dropped.
/// [`Dialed::upgrade`] rather than being dropped, and the attempt falls back to it
/// if the MoQ handshake over WebSocket fails.
///
/// `moq` is the QUIC-side builder, which carries the SETUP path for a raw QUIC dial.
/// The WebSocket fallback uses the plain builder: qmux over WebSocket carries the
Expand All @@ -498,7 +499,8 @@ impl Client {
Q: Future<Output = crate::Result<S>> + Unpin + Send + 'static,
S: moq_net::transport::poll::Boxable,
{
let transport = quic_transport(addr.url());
let url = addr.url().clone();
let transport = quic_transport(&url);
let alpns = self.versions.alpns();
let ws_config = self.websocket.clone();
let ws_tls = self.tls.clone();
Expand All @@ -512,9 +514,34 @@ impl Client {
match race_transport_connect(quic, websocket).await? {
TransportRace::Quic(quic) => Ok(Dialed::new(connect_session(moq, quic).await?, transport)),
TransportRace::WebSocket { session, quic } => {
let session = connect_session(&self.moq, crate::transport::Session::new(session)).await?;
let session = match connect_session(&self.moq, crate::transport::Session::new(session)).await {
Ok(session) => session,
Err(err) => {
// The fallback got through but its MoQ handshake did not. A QUIC dial still
// pending may yet connect, bounded by the same deadline as the race.
let err = Error::from(err);
let quic = match quic {
Ok(dial) => {
tracing::warn!(%err, "WebSocket handshake failed; waiting on QUIC");
dial.await
}
Err(quic) => Err(quic),
};
let quic = match quic {
Ok(quic) => quic,
Err(quic) => return Err(race_error(quic, err)),
};
// UDP gets through after all, so the next dial gives QUIC its head start.
crate::websocket::forget(&url);
// Both handshakes failing is still a two-arm loss: a mixed auth pair stays retryable.
let session = connect_session(moq, quic)
.await
.map_err(|quic| race_error(quic.into(), err))?;
return Ok(Dialed::new(session, transport));
}
};
let mut dialed = Dialed::new(session, crate::Transport::WebSocket);
dialed.upgrade = quic.map(|quic| {
dialed.upgrade = quic.ok().map(|quic| {
let moq = moq.clone();
let dial = Box::pin(async move {
let quic = quic.await?;
Expand Down Expand Up @@ -722,11 +749,11 @@ fn setup_authority(url: &Url) -> Option<String> {
#[cfg(all(feature = "websocket", feature = "noq"))]
enum TransportRace<Q, QT, WT> {
Quic(QT),
/// The fallback won. `quic` is the QUIC dial if it was still pending, and `None`
/// when it had already failed.
/// The fallback won. `quic` is the QUIC dial if it was still pending, or the error
/// it had already failed with.
WebSocket {
session: WT,
quic: Option<Q>,
quic: crate::Result<Q>,
},
}

Expand Down Expand Up @@ -758,7 +785,7 @@ where
res = &mut websocket, if !websocket_done => {
match res {
Some(Ok(session)) => {
let quic = (!quic_done).then_some(quic);
let quic = quic_err.take().map_or(Ok(quic), Err);
return Ok(TransportRace::WebSocket { session, quic });
}
Some(Err(err)) => {
Expand All @@ -779,23 +806,30 @@ where
}
}

// Auth is terminal only when both arms refused. A WebTransport-only endpoint
// answers the fallback with 403 while QUIC is still in flight, and reconnect
// treats is_auth() as terminal, so a mixed pair reports the retryable error.
match (quic_err, websocket_err) {
(Some(quic), Some(websocket)) => Err(match (quic.is_auth(), websocket.is_auth()) {
(false, false) => Error::TransportRace {
quic: std::sync::Arc::new(quic),
websocket: std::sync::Arc::new(websocket),
},
(true, false) => websocket,
_ => quic,
}),
(Some(quic), Some(websocket)) => Err(race_error(quic, websocket)),
(Some(err), None) | (None, Some(err)) => Err(err),
(None, None) => Err(Error::ConnectFailed),
}
}

/// The error for a race both arms lost.
///
/// Auth is terminal only when both arms refused. A WebTransport-only endpoint
/// answers the fallback with 403 while QUIC is still in flight, and reconnect
/// treats is_auth() as terminal, so a mixed pair reports the retryable error.
#[cfg(all(feature = "websocket", feature = "noq"))]
fn race_error(quic: Error, websocket: Error) -> Error {
match (quic.is_auth(), websocket.is_auth()) {
(false, false) => Error::TransportRace {
quic: std::sync::Arc::new(quic),
websocket: std::sync::Arc::new(websocket),
},
(true, false) => websocket,
_ => quic,
}
}

#[cfg(any(
feature = "noq",
feature = "iroh",
Expand Down Expand Up @@ -1388,10 +1422,42 @@ mod tests {
};

let value = super::race_transport_connect(Box::pin(quic), websocket).await.unwrap();
assert!(matches!(
value,
super::TransportRace::WebSocket { session: 1, quic: None }
));
let super::TransportRace::WebSocket {
session: 1,
quic: Err(err),
} = value
else {
panic!("WebSocket won after QUIC failed, and must carry the QUIC error");
};
assert!(err.is_auth(), "unexpected error: {err}");
}

/// A QUIC failure that lands before WebSocket connects stays with the race, so a
/// later WebSocket handshake failure combines both arms as `race_error` does.
#[cfg(all(feature = "websocket", feature = "noq"))]
#[tokio::test]
async fn race_transport_connect_keeps_an_earlier_quic_error() {
let quic = async { Err::<usize, _>(Error::ConnectFailed) };
let websocket = async {
tokio::task::yield_now().await;
Some(Ok(1usize))
};

let value = super::race_transport_connect(Box::pin(quic), websocket).await.unwrap();
let super::TransportRace::WebSocket {
session: 1,
quic: Err(err),
} = value
else {
panic!("WebSocket won after QUIC failed, and must carry the QUIC error");
};
assert!(matches!(err, Error::ConnectFailed), "unexpected error: {err}");

let combined = super::race_error(err, crate::ConnectError::Unauthorized.into());
assert!(
!combined.is_auth(),
"mixed auth/non-auth must stay retryable: {combined}"
);
}

#[cfg(all(feature = "websocket", feature = "noq"))]
Expand Down Expand Up @@ -1536,7 +1602,7 @@ mod tests {
let race = super::race_transport_connect(Box::pin(quic), websocket).await;
let Ok(super::TransportRace::WebSocket {
session: "websocket",
quic: Some(quic),
quic: Ok(quic),
}) = race
else {
panic!("WebSocket won, and the QUIC dial it beat must come back with it");
Expand Down
Loading
Loading