ThomDietrich / home-assistant-addons

AutoSSH Home Assistant Addon - alternative to cloud or VPN: Permanent port forwarding
MIT License
32 stars 18 forks source link

Addon stops when connection/forwarding fails #17

Open ThomDietrich opened 8 months ago

ThomDietrich commented 8 months ago

We had a power outage today. This lead to a weird constellation in which the autossh-addon wasn't able to connect and stopped after the run script was finished.

I assume there are similar causes for connection issues and I would like to ensure that the addon never stops trying to reconnect.

I see three options to fix this:

  1. Fix my specific issue by setting the following line to "no" - not sure what that will do exactly https://github.com/ThomDietrich/home-assistant-addons/blob/01dce2b79dda9e6488c66bec46826f52f6ff3f57/autossh/run.sh#L83
  2. Put the autossh command into an endless loop - that would certainly help
  3. Make use of supervisor watchdog "will restart the addon when it fails" - I don't know how it works and what fails means. Is it a simple exit 1?

Option 3 is my favorite overall.

What do you think?

Rjevski commented 1 month ago

I've encountered this issue a few times now so I'm keen to get this resolved.

Option 1 will not do anything. That setting only controls the behavior of the SSH client process when the SSH connection itself succeeded but forwarding the port failed (let's say the remote port is already occupied on the remote host).

In our case the issue is very likely to be networking (the add-on starts trying to connect before the network connection is up) so we wouldn't even get to a stage where that setting becomes relevant anyway, but even if it did, having ssh stay running after failing to forward the port would be useless to us anyway.

Option 2 is the solution.

Option 3 is not a full solution. I have it enabled and yes it looks like it behaves like you described. The problem is that it has a max number of restarts and/or has a "burst" limit where lots of restarts in a short time will cause the watchdog to give up.

ThomDietrich commented 1 month ago

@Rjevski thanks for your response. I favored option 3 under the assumption that this watchdog behavior can be influenced. It did follow an infinite restart pattern some time ago and the "giving up" strategy is changed behavior since then. I wonder if that can be configured per add-on, which would make this the best solution. Long story short: I never looked into the behavior of the watchdog. Do you have any further knowledge?

After we have rules out option 3 as a viable option, I am more than happy to implement option 2 or to accept a PR.

Rjevski commented 1 month ago

I have opened the PR above - would you be able to test the following: