antoniomika / sish

HTTP(S)/WS(S)/TCP Tunnels to localhost using only SSH.
https://ssi.sh
MIT License
4.03k stars 308 forks source link

[Question] - Keep the connection stable and avoid client restart #308

Closed manprint closed 5 months ago

manprint commented 5 months ago

Hi @antoniomika

I noticed, looking at the logs of the ssh client connected to the sish server, that there are frequent disconnections and restarts (the client is managed with autossh or systemd service).

The sish server is deployed on an AWS machine and my clients are also almost all on AWS so I don't think that the disconnections are caused by connection problems (in general the EC2 AWS have stable connections)

When the client logs out they show the message:

Connection to sish.mydomain.link closed by remote host.
Connection to sish.mydomain.link closed.

What can I do to avoid these frequent disconnections? Should I use, client-side, ssh with any of the following parameters? (If so, what values ​​do you recommend?)

-o ServerAliveInterval=??
-o ServerAliveCountMax=??
-o TCPKeepAlive=??

The parameters I use on the server side are these:

--idle-connection=true \
--idle-connection-timeout=5s \
--cleanup-unauthed=true \
--cleanup-unauthed-timeout=5s \
--cleanup-unbound=true \
--cleanup-unbound-timeout=5s \
--ping-client=true \
--ping-client-interval=5s \
--ping-client-timeout=5s \

Do you have any recommendations or tips for keeping the connection alive and avoiding frequent client restarts? Are the values ​​set on the sish server adequate to keep the connection stable and avoid restarts?

Thank You. Fabio

antoniomika commented 5 months ago

Hello @manprint ,

The connection being closed by remote host makes me think that the connection is either unbound (no tunnel) or unauthed (just staying at password auth). The ServerAliveInterval should be at least the ping-client-interval (usually a bit more for buffer).

Could you share the full sish command you are using as well as the full autossh command? It could have something to do with the tunnels being used.

Also, any logs from sish (and exit codes, just in case sish is the thing that is crashing) would be helpful as well!

manprint commented 5 months ago

Hi, Thanks for your quick response.

This is my typical command when running sish with autossh:

autossh -M 0 -p 2222 -R subdomain:80:localhost:5000 sish.mydomain.it

I checked the sish logs and there are no crashes.

antoniomika commented 5 months ago

Hrm yeah, there's nothing complicated going on there then. I would try the ping-interval and timeout modifications.

The other thing it could be is something with the autossh monitoring forward acting weird? Though not sure why that would be.

manprint commented 5 months ago

Ok, let's try changing the timeout and ping-interval settings. Do you have any values ​​to suggest?

manprint commented 5 months ago

Hi @antoniomika

I'm testing with the following parameters:

--ping-client=true \
--ping-client-interval=30s \
--ping-client-timeout=30s \

The autossh command I'm using is the following:

autossh -M 0 -o "ServerAliveInterval 35" -o "ServerAliveCountMax 2" -p 2222 -R mysubdomain:80:localhost:5000 sish.mydomain.it

What do you think about it? Suggestions?

antoniomika commented 5 months ago

Those look good to me! Let me know how it goes!

manprint commented 5 months ago

Ok, thanks. I'll leave it like this and check. I'll let you know soon.

Fabio

manprint commented 5 months ago

Hi @antoniomika

I tested with the settings I wrote above. The connection is much more stable. In three days there was only one disconnection.

Thanks as always for the support.

Fabio

antoniomika commented 5 months ago

Awesome! I'm gonna close this for now! Again, if you're happy with sish and the work I'm doing, please consider sponsoring the project!

Best,

Antonio