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
9 changes: 3 additions & 6 deletions rs/moq-net/src/reconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
//!
//! The first walk of the peer's addresses fails fast: if no address establishes a
//! session, the policy ends with [`Action::Done`] carrying that walk's error rather than
//! retrying, so a setup mistake surfaces at once instead of looping. The one exception is
//! a refused credential the tokens have replaced since, which earns another dial. A client started
//! retrying, so a setup mistake surfaces at once instead of looping. A client started
//! before its peer is reachable therefore exits, for its supervisor or app to restart.
//! Once a session has been established, a later failure backs off and retries under
//! [`Backoff`], so restarts and redeploys still recover.
Expand Down Expand Up @@ -55,8 +54,7 @@ const PROBE_MAX: Duration = Duration::from_secs(300);

/// When to redial after a failure, and when to give up, once a session has been established.
///
/// Before then nothing retries: the first walk ending without a session ends the policy,
/// unless the peer refused credentials the tokens have replaced since.
/// Before then nothing retries: the first walk ending without a session ends the policy.
///
/// `initial` and `multiplier` set the wait before each retry, `max` caps it, and
/// `healthy` decides which sessions count as failed attempts. The delays carry jitter,
Expand Down Expand Up @@ -508,8 +506,7 @@ impl<A: Target, E: Clone + std::fmt::Display + From<Error> + From<Failure>> Reco

/// Present `tokens` on every dial, through [`Attempt::client`].
///
/// A refused credential then earns another dial once the tokens change, and an ended
/// tokens handle ends the policy at its next walk.
/// An ended tokens handle ends the policy at its next walk.
pub fn with_tokens(mut self, tokens: auth::Tokens) -> Self {
self.tokens = Some(tokens);
self
Expand Down
5 changes: 3 additions & 2 deletions test/interop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ released relays and clients, skip it.
Whenever the browser subscriber is in the run, the matrix ends with a close-code
case: Chromium dials the relay with a token its public rules refuse, and
`WebTransport.closed` must carry the relay's code and reason. A WebSocket-only
`Connection` must publish the same Unauthorized session error and stop its
unlimited reconnect loop. Chromium treats a
`Connection` counts the refused session as connected, so it must redial it
like any other close and, once a short retry window runs out, publish the same
session error. Chromium treats a
server's HTTP/3 control stream ending as fatal, so a server that ends it under
the close capsule loses both; no Rust peer is that strict.

Expand Down
3 changes: 2 additions & 1 deletion test/interop/clients/js/close.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Proves a relay's rejection reaches the page over WebTransport and WebSocket.
* WebTransport.closed has to carry the relay's code; a WebSocket Connection has
* to publish its MalformedAuthToken session error and stop reconnecting.
* to redial the refused session within its retry window, then publish its MalformedAuthToken
* session error.
*
* Chromium treats the server's HTTP/3 control stream ending as fatal, so a server that ends it
* alongside the CLOSE_WEBTRANSPORT_SESSION capsule turns the close into a bare connection error.
Expand Down
23 changes: 19 additions & 4 deletions test/interop/clients/js/src/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* @module
*/
import { Duration } from "@moq/clock";
import { Connection, Error as MoqError } from "@moq/net";
import type { CloseState } from "./contract";

Expand Down Expand Up @@ -41,20 +42,34 @@ export async function refused(relay: string): Promise<CloseState> {
return closed;
}

/** A WebSocket refusal reaches the reconnecting handle as a terminal session error. */
/**
* A WebSocket refusal reaches the reconnecting handle as its session error.
*
* The relay closes a session that ALPN already established, so the handle redials it like any
* other close until its retry window runs out, then publishes the last close.
*/
export async function refusedWebSocket(relay: string): Promise<CloseState> {
const url = new URL(relay);
url.protocol = "ws:";
url.searchParams.set("jwt", "refused");
const connection = new Connection({ url, share: false });
const connection = new Connection({
url,
share: false,
delay: { initial: Duration.millis(200), max: Duration.millis(200), timeout: Duration.secs(2) },
});
// Every refused session counted as connected first; a second one proves the handle redialed.
let connected = 0;
const dispose = connection.status.subscribe((status) => {
if (status === "connected") connected++;
});
try {
// The default retry window is unlimited. An error is published only once
// Reload stops this URL, so observing it proves the rejection is terminal.
let error = connection.error.peek();
while (!error) error = await connection.error.changed();
if (connected < 2) return { error: `gave up after ${connected} session(s) instead of redialing: ${error}` };
if (!(error instanceof MoqError.Session)) return { error: String(error) };
return { closeCode: error.code, reason: error.message };
} finally {
dispose();
connection.close();
}
}
3 changes: 2 additions & 1 deletion test/interop/interop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,8 @@ run_matrix() {
done

# The relay refuses a token that is not a JWT, and Chromium has to read the close code and
# reason it sends. WebSocket must surface MalformedAuthToken and stop reconnecting too.
# reason it sends. WebSocket must redial the refused session within its retry window, then
# surface MalformedAuthToken.
# Chromium is the strict peer here, so no Rust client stands in for it. The relay refuses
# before any version is negotiated, so one pass covers it.
if [[ "$VERSION" == auto ]] && needs js; then
Expand Down