feat(rust): Implementation of missing RUST feature#603
Open
thechandanbhagat wants to merge 12 commits intomicrosoft:mainfrom
Open
feat(rust): Implementation of missing RUST feature#603thechandanbhagat wants to merge 12 commits intomicrosoft:mainfrom
thechandanbhagat wants to merge 12 commits intomicrosoft:mainfrom
Conversation
The Rust RelayTunnelHost supports reconnection — callers can reuse the same RelayTunnelHost instance and call connect() again after a dropped connection. Update the SDK Feature Matrix to reflect this.
There was a problem hiding this comment.
Pull request overview
Updates the repository’s SDK Feature Matrix documentation to accurately reflect that the Rust SDK supports reconnection (aligning README with the Rust RelayTunnelHost::connect() guidance mentioned in the PR description).
Changes:
- Marked Reconnection as supported (✅) for the Rust SDK in the README feature matrix.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add connect_persistent() to RelayTunnelHost with automatic reconnection: - New connect_persistent() method wraps relay_connect_once() in a retry loop - Exponential backoff: starts at 1s, doubles up to 13s cap (matching TS SDK) - Returns PersistentRelayHandle with watch::Receiver<RelayConnectionState> - Stop the reconnect loop cleanly by dropping or calling .stop() on the handle - Fail-fast: first connection attempt is made eagerly before spawning the loop - Max retry limit supported via ReconnectOptions.max_attempts (None = infinite) New types: - RelayConnectionState enum (Connected / Reconnecting / Disconnected) - ReconnectOptions struct (max_attempts, initial_delay_ms, max_delay_ms) - PersistentRelayHandle (state receiver, stop signal, join handle) Refactored connect() to delegate to new relay_connect_once() free function, and extracted create_websocket() to create_relay_websocket() free function so both connect() and connect_persistent() can share connection logic. Closes the feature gap with the TypeScript SDK's RelayTunnelConnector reconnect loop.
…nnection - Add KeepAliveState enum (NotConfigured, Succeeded/Failed with count) - Add keep_alive_interval and token_refresher fields to ReconnectOptions - Add keep_alive: Receiver<KeepAliveState> to PersistentRelayHandle - Rewrite connect_persistent() with: - SSH-level reconnect: skip delay and reset backoff on TunnelRelayDisconnected - Auto token refresh: retry on HTTP 401 via configurable token_refresher callback - Keep-alive channel plumbing to relay_connect_once - Update relay_connect_once() with keep_alive param and background probe task - Add TokenRefreshFailed error variant to TunnelError - Update README rows 16-18 Rust column: SSH reconnection, token refresh, keep-alive - Add unit tests: KeepAliveState variants, backoff cap, skip_delay, ReconnectOptions defaults
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 11 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements automatic reconnection support in the Rust SDK, closing the feature gap with the TypeScript SDK's
RelayTunnelConnectorreconnect loop.Previously the Rust SDK had no automatic reconnection — callers had to detect disconnection and call
connect()manually. This PR adds:connect_persistent()— a new method onRelayTunnelHostthat wraps the relay connection in a retry loop with exponential back-offconnect()andconnect_persistent()share the same connection logicNew API
New types
RelayConnectionStateConnected/Reconnecting { attempt, delay_ms }/DisconnectedReconnectOptionsmax_attempts,initial_delay_ms,max_delay_msPersistentRelayHandleconnect_persistent()— holds state receiver + stop signalImplementation Details
connect_persistent()so callers surface configuration errors immediately (no background goroutine races)max_delay_ms(default 13 s, matching TypeScript behaviour)PersistentRelayHandle(or calling.stop()) signals the reconnect loop to exit gracefullyselect!during the sleep also listens for a stop signal so shutdown is responsive even while waitingconnect()now delegates torelay_connect_once(), andconnect_persistent()calls it in a loop — no code duplicationBackoff behaviour (mirrors TypeScript
RelayTunnelConnector)Files Changed
rs/src/connections/relay_tunnel_host.rsconnect_persistent(), new types, extracted free functionsrs/src/connections/errors.rsMaxReconnectAttemptsExceeded(u32)error variantREADME.mdTesting
Rust Analyzer (via VS Code) reports no errors. An OpenSSL system dependency prevents running
cargo buildlocally on Windows without vendored OpenSSL — the logic has been cross-referenced against the equivalent TypeScript implementation ints/src/connections/relayTunnelConnector.ts.Code of Conduct