A
A
Anton Ivanov2018-04-19 09:25:38
C++ / C#
Anton Ivanov, 2018-04-19 09:25:38

Why does the request take much longer to resolve an IPv6 address?

Hello.
I'm making requests to my domain from a C++ application.
Requests are made using functions from WinInet.h, that is,
InternetOpen -> InternetConnect -> HttpOpenRequest -> HttpSendRequest
I noticed that for some people requests are executed instantly, for others it takes a very long time (about 20-30 seconds per request). Found out that the point is which address is resolved. If it's ipv6, then everything is slow. If I am on a machine where the ipv6 address is resolved by hand, I prescribe the domain address in hosts ipv4, then everything starts working very quickly.
I honestly googled but didn't find anything similar.
Here is a code snippet:

hInet = InternetOpen(string("MyApp/" + AppVersionAsString).c_str(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (!hInet) return false;

hConn = InternetConnect(hInet, appDomain.c_str(), 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, dwContext);
if (!hConn) return false;

DWORD dwFlags = INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI | INTERNET_FLAG_PRAGMA_NOCACHE;
hReq = HttpOpenRequest(hConn, "POST", path.c_str(), "HTTP/1.1", NULL, rgpszAcceptTypes, dwFlags, dwContext);

DWORD connectTimeout = 5000;
InternetSetOption(hReq, INTERNET_OPTION_CONNECT_TIMEOUT, &connectTimeout, sizeof(connectTimeout));

bSuccess = HttpSendRequest(hReq, headers.c_str(), headers.length(), (LPVOID)PostData.c_str(), PostData.size());

I will add: brakes only the first request. Subsequent ones are fast even on ipv6

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anikavoi, 2018-04-19
@anikavoi

Most likely it's the difference between the DNS servers involved in the resolve.
Try to set 8.8.8.8 or 1.1.1.1 as the DNS server on all tested, and compare.
If the effect remains, then ... I don't know.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question