2.12. Reconnection¶
When an established Teleport session loses its real-time transport (the WebRTC peer connection drops, the WebSocket closes, or the underlying network goes away) the client does not immediately tear down its local reflection of the remote scene. Instead it tries a bounded number of times to re-establish the session with the same server, and only gives up — clearing the geometry cache and stopping rendering of the remote content — when those attempts have all failed.
2.12.1. Triggering a reconnect¶
The reference client samples avs::StreamingConnectionState (exposed by
avs::WebRtcNetworkSource) once per frame. A transition from
CONNECTED to any of DISCONNECTED, FAILED or CLOSED is treated
as a drop of an established session and triggers reconnection, but only if the
client had previously completed a setup handshake (lastSessionId is
non-zero); an initial-connect failure is left to the user to retry.
2.12.2. State machine¶
The new RECONNECTING value is added to
teleport::client::ConnectionStatus. While the client is in
RECONNECTING it does not send a disconnect JSON frame to the server —
it keeps the previous clientID and serverID so that the server can
match the next connect as a continuation of the session.
2.12.3. Back-off¶
Each time the per-attempt deadline (Options::connectionTimeout) elapses
without a connect-response, the back-off doubles, clamped to
Options::reconnectMaxBackoffMs. The first wait is
Options::reconnectInitialBackoffMs. After
Options::maxReconnectAttempts failed attempts the client gives up.
2.12.4. Configuration¶
The reconnection behaviour is controlled by three fields on
teleport::client::Options, persisted in options.txt under the
keys MaxReconnectAttempts, ReconnectInitialBackoffMs and
ReconnectMaxBackoffMs:
Field |
Default |
Meaning |
|---|---|---|
|
|
Number of attempts before giving up. Set to |
|
|
Wait before the first attempt, in milliseconds. |
|
|
Upper bound for the back-off, in milliseconds. Each subsequent attempt doubles the previous wait and is clamped to this value. |
2.12.5. Server-ID matching¶
A reconnect is only treated as a continuation of the previous session when
the serverID returned in the connect-response matches the one the
client recorded for the previous successful connection.
If
clientIDandserverIDboth match the values the client already holds,teleport::client::SignalingServerclears itsclearResourcesflag.SessionClient::HandleConnectionsthen preserves the geometry cache, and the nextSetupCommandarriving with the samesession_idallows the client to skip re-acknowledging resources it has already cached.If either id differs (for example because the server application has restarted and considers itself to be running a new state),
SignalingServeradopts the new ids and signalsDiscoveryService::ShouldClear.SessionClientthen drops the geometry cache before completing the new setup, exactly as for a first-time connection to a fresh server.
2.12.6. Giving up¶
When the maximum number of attempts is exhausted, the client:
Tears down the streaming pipeline (
ClientPipeline::pipeline.deconfigure()andsource->deconfigure()).Calls
teleport::client::SessionCommandInterface::OnReconnectGaveUp()on the renderer. The referenceteleport::clientrender::InstanceRendererresponds by closing the video stream and clearing the geometry cache, so the local reflection of the remote scene is no longer drawn.Clears the geometry cache associated with the session.
Performs a clean
teleport::client::SessionClient::Disconnect(), resettingclientIDand sending adisconnectframe to the server (if the WebSocket is still open).Returns to
UNCONNECTED. A subsequent user action (clicking a bookmark, re-typing the URL) is needed to start a new session.
2.12.7. Surfacing transport drops¶
To make reconnection responsive, the WebRTC network source pushes its state to
DISCONNECTED as soon as a send call fails because the channel is
closed, in addition to the normal onStateChange callback. This guarantees
that the next Frame call observes the drop without waiting for the peer
connection’s own state machine to catch up.