antoniomika / sish

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

Autossh reconnection issue with sish #309

Open manprint opened 2 weeks ago

manprint commented 2 weeks ago

Hi @antoniomika,

I think I found an issue when using sish with autossh. After starting sish with autossh with the following command, for example:

autossh -M 0 -p 2222 -R pico16-a:80:localhost:8004 sish.mydomain.link

When you want to stop the tunnel, since autossh automatically reconnects the tunnel, you have to press CTRL+C several times in rapid succession to stop sish session and exit autossh.

if you try to reconnect to the same domain sish says:

Warning: remote port forwarding failed for listen port 80
The subdomain pico16-a.sish.mydomain.link is unavailable.

In order to reuse the blocked domain, sish must be restarted the problem is probably due to the fact that sish is very quick to reconnect. I managed to replicate the issue several time.

A possible solution to mitigate the problem could be a parameter to delay the ssh connection when ssh is invoked? (--ssh-connection-delay=5s)

If you need to do further tests I can help you.

Best, Fabio.

manprint commented 2 weeks ago

Hi, I did further tests and when what I described above happens, this is in the sish server logs:

2024/06/17 - 18:58:35 | Accepted SSH connection for: 172.18.0.3:53570
2024/06/17 - 18:58:35 | HTTP forwarding started: http://test.dev.synclabapps.link -> /tmp/172.18.0.3_53564_80332338001 for client: 172.18.0.3:53564
2024/06/17 - 18:58:35 | HTTPS forwarding started: https://test.dev.synclabapps.link -> /tmp/172.18.0.3_53564_80332338001 for client: 172.18.0.3:53564
2024/06/17 - 18:58:35 | Error replying to port forwarding request: read tcp 172.18.0.2:2222->172.18.0.3:53564: use of closed network connection
2024/06/17 - 18:58:36 | EOF
2024/06/17 - 18:58:51 | Accepted SSH connection for: 172.18.0.3:35654
2024/06/17 - 18:58:51 | Login attempt: 172.18.0.3:35654, user fabio key: ssh-rsa (REDACTED)
2024/06/17 - 18:58:51 | Error setting up HTTPListener: error assigning requested subdomain to tunnel

Step to reproduce the issue:

1) start tunnel with autossh -M0 -p 2222 -R test:80:localhost:8080 dev.mydomain.link 2) wait for 30+ seconds for the gate time (AUTOSSH_GATETIME=30 (default)) to finish 3) repeatedly press or hold CTRL+C to stop sish session and autossh

I hope it helps you. Best, Fabio

zk-steve commented 2 weeks ago

sish will close unused connections (include closed ones) by default, unless you mess something up with your configuration.

Otherwise, you can try to set:

force-requested-subdomains = true,

antoniomika commented 4 days ago

Agree with setting force-requested-subdomains.

I’m still looking into this as I’m wondering if maybe it has something to do with autossh’s monitor port.

synclab-srl commented 4 days ago

Hi, I tried the setting you recommended, but it didn't work. The problem persists. I attach a video of the test case in which the problem is highlighted. I hope it can be of use to you.

https://github.com/antoniomika/sish/assets/162589296/33ca7a46-1c2a-47e3-820b-6e4eabdfc823

Best, Fabio