Feature: use Happy Eyeballs to make network connections (TCP-only) #9199
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
From time to time we get reports that the Online Content list not loading (#9198, #8582, https://www.tt-forums.net/viewtopic.php?f=31&t=66905 ) is the most common case. In 99.99% of these cases, the problem is the IPv6 setup of the local machine: the OS things IPv6 is functional (
getaddrinfo
reports IPv6 as preferred, an IPv6 socket can be created, etc), but the connection is never really established. As this is a problem on OS level, OpenTTD cannot really resolve the issue.This problem is most noticeable with TCP, as for UDP we basically just send out our request on what-ever interface we can find, and it is more likely it will find its way (up-side of stateless sockets). So we do not see many reports of people that cannot load the multiplayer list.
With the upcoming STUN support, we switch the multiplayer list to TCP too. This means that it is more likely people will notice this problem, and cannot play multiplayer. So, the question is: can't we do a similar solution like browers: try both IPv6 and IPv4, and see which one works. This, as dwfreed on IRC pointed out, is called Happy Eyeballs.
This PR sets out to implement exactly this: try both IPv6 and IPv4 (if available), in a smart way to not hurt our servers too much. As added benefit, it also means the round-robin DNS we use is used a bit smarter: if the first IPv4 doesn't work (times out), the second is already tried after 250ms instead of after 3s.
Description
Limitations
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.