Skip to content

Conversation

sladkani
Copy link
Contributor

@sladkani sladkani commented May 8, 2025

Currently in reverse-tunnel mode, upon errors when client tries to establish the connection to the remote server, 'run_reverse_tunnel' simply retries every 1s.

This might be too agressive in certain scenarios, for example when the tunnel server (or a load-blancer in front of it) is not yet ready and returns 503. Another example is when the tunnel server does not agree on the tunnel parameters.

Implement an exponential backoff for the delay between reconnect attempts. The maximum reconnect delay is controlled by setting "--reverse-reconnect-max-delay". The default is "1s" in order to keep existing behavior.

… errors

Currently in reverse-tunnel mode, upon errors when client tries to establish
the connection to the remote server, 'run_reverse_tunnel' simply retries
every 1s.

This might be too agressive in certain scenarios, for example when
the tunnel server (or a load-blancer in front of it) is not yet ready
and returns 503. Another example is when the tunnel server does
not agree on the tunnel parameters.

Implement an exponential backoff for the delay between reconnect
attempts. The maximum reconnect delay is controlled by setting
"--reverse-reconnect-max-delay". The default is "1s" in order to keep
existing behavior.
@erebe
Copy link
Owner

erebe commented May 9, 2025

Hello,
Going to check in the coming days 👍

@@ -133,6 +137,9 @@ impl WsClient {
remote_addr: RemoteAddr,
connector: impl TunnelConnector,
Copy link
Owner

Choose a reason for hiding this comment

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

The delay should be better configurable per tunnel/connection instead of putting the config globally for the whole client.

You can take as example the timeout parameter, https://github.com/erebe/wstunnel/blob/main/src/tunnel/mod.rs#L41
It should be parsed from the tunnel command line (or use a default value) and passed as parameter in run_reverse_tunnel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack, will try that

@erebe
Copy link
Owner

erebe commented May 11, 2025

Overall looks ok, the PR only needs to make the delay configurable per tunnel :)

@sladkani
Copy link
Contributor Author

Overall looks ok, the PR only needs to make the delay configurable per tunnel :)

actually @erebe , after consideration, i actually think this knob should be global (and not per specific reverse tunnel configuation).
suppose we run wstunnel client with several reverse tunnels:
wstunnel client -R <RTUNNEL-SPEC1> -R <RTUNNEL-SPEC2> -R <RTUNNEL-SPEC3> wss//wstunnel.server.behind.lb

the exponential backoff property is regarding the attempt to communicate with the wstunnel server. we would like to avoid being too aggressive when connecting the server; hence that property makes little sense to configure per RTUNNEL-SPEC - user will most likely choose same value for all.

this property is similar in spirit to the global connection_retry_max_backoff (which control client's connection pool's total timeout for a connect() call).

@erebe
Copy link
Owner

erebe commented May 12, 2025

Ok fair enough.

I am going to merge the PR and make a new release tomorrow.

By the way and out of curiosity what are you using wstunnel for ?

@sladkani
Copy link
Contributor Author

Ok fair enough.

I am going to merge the PR and make a new release tomorrow.

Thanks!
I'm about to send an additional small PR (yet another knob addition), if you're interested to wait with the next release.

@erebe erebe merged commit 04fe30d into erebe:main May 13, 2025
13 checks passed
@sladkani
Copy link
Contributor Author

I am going to merge the PR and make a new release tomorrow.

Thanks! I'm about to send an additional small PR (yet another knob addition), if you're interested to wait with the next release.

Hi @erebe

No plans for an additional PR eventually.

Would appreciate if you can create a new release.

Many thanks!

@erebe
Copy link
Owner

erebe commented May 13, 2025

It is released in https://github.com/erebe/wstunnel/releases/tag/v10.3.0

In case you haven't seen it, I have renamed the parameter into reverse_tunnel_connection_retry_max_backoff to align the naming with the other already existing parameters

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