Skip to content

client: add automatic tunnel re-registration on connection failures#45

Merged
kaichaosun merged 1 commit into
kaichaosun:mainfrom
gdesmott:registration
Jun 5, 2026
Merged

client: add automatic tunnel re-registration on connection failures#45
kaichaosun merged 1 commit into
kaichaosun:mainfrom
gdesmott:registration

Conversation

@gdesmott

Copy link
Copy Markdown
Contributor

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.

Comment thread client/src/lib.rs Outdated
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.

@kaichaosun kaichaosun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kaichaosun
kaichaosun merged commit 0c4d14f into kaichaosun:main Jun 5, 2026
3 checks passed
@gdesmott

gdesmott commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

Any chance to have a release with the changes? :)

@gdesmott
gdesmott deleted the registration branch June 5, 2026 21:17
@kaichaosun

Copy link
Copy Markdown
Owner

@gdesmott v0.1.7 is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants