Discussion:
Happy Eyeballs mechanism may start from IPv4 family if c-ares resolver reply for IPv6 comes first.
Dmitry Karpov via curl-library
2021-06-03 20:11:29 UTC
Permalink
Hello,

Trying dual-stack on some embedded platform, I noticed that quite frequently (20%) libCurl starts from IPv4 regardless the Happy Eyeballs timeout value.
After debugging this issue, I noticed that this happens if c-ares resolver response for IPv6 family comes before IPv4 (which was randomly happening in my tests).

In such cases, because libCurl puts the last resolver response on top of the address list, when IPv4 resolver response comes after IPv6 one - the IPv4 family starts the connection phase instead of IPv6 family.

A potential solution for this issue can be always putting IPv6 addresses on top of the address list, regardless the order of resolver responses.

Here is the proposed fix for c-ares resolver that helped to mitigate the problem:

Changing the compound_results() function in lib\asyn-ares.c to the following:

/* Connects results to the list */
static void compound_results(struct ResolverResults *res,
Curl_addrinfo *ai)
{
if(!ai)
return;

/* Add the new results to the list of old results. */
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
if (res->temp_ai && res->temp_ai->ai_family == PF_INET6) {
/* We have some results already and we need to make sure that IPv6 entries
always go to the head of the list. */
Curl_addrinfo* temp_ai_tail = res->temp_ai;

while (temp_ai_tail->ai_next)
temp_ai_tail = temp_ai_tail->ai_next;

temp_ai_tail->ai_next = ai;
}
else
#endif /* CURLRES_IPV6 */
{
Curl_addrinfo* ai_tail = ai;

while (ai_tail->ai_next)
ai_tail = ai_tail->ai_next;

ai_tail->ai_next = res->temp_ai;
res->temp_ai = ai;
}
}

This change makes sure that IPv6 addresses are always put on top of the address list.

Unfortunately, I didn't have time to check the other resolvers - we use only c-ares, but they should be probably checked as well.

Thanks,
Dmitry Karpov
Daniel Stenberg via curl-library
2021-06-03 20:58:15 UTC
Permalink
Thanks!

Any chance you can make a pull-request out of this and submit it at
https://github.com/curl/curl/pulls ?

If not, I can do it for you.
--
/ daniel.haxx.se
| Commercial curl support up to 24x7 is available!
| Private help, bug fixes, support, ports, new features
| https://www.wolfssl.com/contact/
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.se/mail/et
Dmitry Karpov via curl-library
2021-06-03 21:08:49 UTC
Permalink
Hi Daniel,

We currently don't use Git as a our source control system, but I will try to do a pull request today.
If I have difficulties, I will ask for your help.

Thanks,
Dmitry Karpov


-----Original Message-----
From: Daniel Stenberg <***@haxx.se>
Sent: Thursday, June 3, 2021 1:58 PM
To: Dmitry Karpov via curl-library <curl-***@cool.haxx.se>
Cc: Dmitry Karpov <***@roku.com>
Subject: Re: Happy Eyeballs mechanism may start from IPv4 family if c-ares resolver reply for IPv6 comes first.
Thanks!

Any chance you can make a pull-request out of this and submit it at https://github.com/curl/curl/pulls ?

If not, I can do it for you.
--
/ daniel.haxx.se
| Commercial curl support up to 24x7 is available!
| Private help, bug fixes, support, ports, new features
| https://www.wolfssl.com/contact/

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.se/mail/etiquette
Loading...