Skip to main content

Module reconnect

Module reconnect 

Source
Expand description

Client connect policy: which of a peer’s addresses to dial, how long each dial may take, when to back off and when to give up, and how to follow a GOAWAY.

Reconnect is a poll machine that does no I/O. The caller dials each Attempt it asks for, reports the result with Reconnect::connected or Reconnect::failed, and otherwise polls it with the current time. The machine watches each live session for its close and GOAWAY itself, keeps a drained predecessor serving through its handover, and drops neither on the caller’s behalf until it reports Action::Done. A connected session serves only once the machine reports it Action::Established, so a caller never shows a refusal as connected.

The policy fails fast until a session is established: the peer accepts the connection credential (its SETUP, or on moq-lite-07-wip the AUTH_OK to the connection’s own credential) or drains the session with a GOAWAY. On moq-lite 03/04, which answer the credential with nothing, staying up past Backoff::healthy establishes it too; a version with an answer waits for it however long the session stays up. A failed walk, or a session closed before then, ends the policy with Action::Done carrying that error rather than retrying, so a setup mistake surfaces at once instead of looping. That covers a peer that refuses the session right after connecting, as a relay rejecting a token on moq-lite 03 or later does. 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. A policy given Dials fails fast the same way; once established, the caller reads why each redial follows a failure on Dial::failure and ends the policy by failing the dial.

A caller whose session landed on a fallback transport says so with Reconnect::fallback. The machine then asks for Action::Probes of the preferred transport on a slow backoff and, once one gets through, moves to it through the same handover a GOAWAY uses: the old session drains, and on lite-07 its live tracks continue on the replacement. lite-05/06 carry no instance, so their tracks end when the old session does.

Structs§

Attempt
One dial the caller runs for Reconnect.
Backoff
When to redial after a failure, and when to give up, once a session has been established.
Config
The whole connect policy for one peer.
Dial
One dial of a reconnecting connection, waiting for the tokens it presents.
Dials
Tokens a reconnecting connection asks for at each dial, for a credential that must be fresh when it is presented, such as a proof a peer admits once and only shortly after it was signed.
Handover
How a connection hands over to a new session after a peer’s GOAWAY.
Reconnect
Client connect policy as a poll machine; see the module docs.

Enums§

Action
What Reconnect::poll asks of the caller.
ConfigError
Invalid input to Reconnect::new.
Failure
A failure the policy itself decides on.
Redirect
What to do with the URI a peer names in its GOAWAY.
Restart
What to do when a peer’s GOAWAY names no URI, meaning it is restarting where we reached it.
Verdict
What a failed dial means for the address walk, judged by the caller from the address and the peer’s answer rather than the error’s kind.

Traits§

Target
One of a peer’s addresses, as the caller dials it.