When the routing issue is fixed, the connection will restore itself.
The problem is not that I need a backup link, it's that mosquitto will always retry the same address.
For example:
Server: 127.0.0.1
Address 1: 127.0.0.1 localhost
Address 1: 1234:1234:3::1234:1234 --> IPv6 not reachable
If I try to connect to
broker.domain.com, mosquitto will always try to connect to the first in the list of resolved ip-addresses.
If it thinks it has a valid route, it will try and connect. However if this connection times out, on the next attempt it will again select the same address instead of choosing a different one.
The order in which the resolved ip-addresses are returned is random, however the IPv6 addresses are returned first.
For my use-case, I cannot always guarantee that the IPv6 route is valid, so in some cases this connection will keep timing out.
Just disabling IPv6 on my device is not an option because if it's available, I want to use it.
My patch will make sure that if an attempt was made to an IPv6 address, and it fails, the next time it will skip IPv6 and try over IPv4.
This problem is not uncommon as IPv6 networks around the world are not always known for their reliability.
Other applications (eg. cUrl) use the previously mentioned 'Happy Eyeballs' algorithm to get around this issue.