client: add automatic tunnel re-registration on connection failures#45
Merged
Conversation
kaichaosun
reviewed
Jun 1, 2026
When the remote endpoint becomes unreachable (the server cleaned up our listener port, restarted, or the network path changed), the client now automatically re-registers a fresh endpoint instead of retrying a dead port forever. A supervisor owns a register -> connect -> detect-failure -> re-register cycle; re-registration uses exponential backoff (2s..60s) and keeps the same subdomain so the public tunnel URL stays stable. The trigger is time-based: re-registration fires only once the remote has been *continuously* unreachable for 'reregister_after' (default 30s), rather than after a fixed number of failures. This decouples the trigger from connection concurrency, so a brief blip that keepalive + reconnect can ride out won't force a costly re-registration. The window is configurable via ClientConfig::reregister_after. Endpoint health is tracked by RoundHealth, which records the last time the remote was known reachable. It is refreshed both when a connection is established and when an established connection ends, so an idle tunnel that drops measures downtime from the drop rather than from when it first connected. Includes unit tests for the downtime logic and an integration test covering the full re-register-on-failure flow. The public API (open_tunnel) is unchanged aside from the new optional ClientConfig::reregister_after field.
Contributor
Author
|
Thanks for the review. Any chance to have a release with the changes? :) |
Owner
|
@gdesmott v0.1.7 is released. |
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.
When the remote TCP connection fails repeatedly (10 consecutive failures), the client now automatically re-registers with the server to get a fresh endpoint port, then restarts all connections. This handles the case where the server has cleaned up the client entry or the network path changed.
Re-registration uses exponential backoff (2s to 60s) and respects the shutdown signal throughout.
The public API (open_tunnel/ClientConfig) is unchanged.