curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: DNS data not refreshed after CURLOPT_DNS_CACHE_TIMEOUT

From: Narasimha M via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 1 Sep 2020 22:06:04 +0530

Thanks Daniel and David for the explanations. I think now I
fairly understand the concept of DNS cache timeout.
I will do some tests and get back here if I have any questions.

On Tue, Sep 1, 2020 at 1:35 PM David Requena via curl-library <
curl-library_at_cool.haxx.se> wrote:

> Dear Narasimha,
>
> It seems to me you're missing the point here if I'm understanding your
> intended use case.
>
> Your intended workflow of connecting and then keep hitting DNS to check
> connection validity does not really make any sense.
> You see, as soon as the host you're connected to changes its ip address
> under your feet, the connection becomes invalid.
> In this circumstance, you need to reconnect to the given hostname, at
> which point, DNS *will* be checked if cache timeout has expired.
>
> In short: "curl doesn't resolve the host name AT ALL when it reuses an
> existing connection. It doesn't need to so it avoids it"
> And rightly so.
> By the time you see the change in DNS, you've already been unable to talk
> to the old ip address for some time.
>
> This way, the only timeout you ought to be concerned with should be TCP
> timeout, if any.
> DNS has nothing to do with a *live* connection.
>
> A much saner workflow would be simply to connect, keep using this
> connection until it becomes invalid, then reconnecting.
>
> Hope this helps clearing things out.
>
> Regards
>
> El mar., 1 sept. 2020 a las 9:07, Narasimha M via curl-library (<
> curl-library_at_cool.haxx.se>) escribió:
>
>> OK. So in the given example from man page, if I add a sleep between two
>> easy performs, should the application resolve the name?
>>
>> ret = curl_easy_perform(curl);
>> /* in this second request, the cache will not be used if more than
>> two seconds have passed since the previous name resolve */
>> sleep(5); /* add a sleep of five seconds, so as to force a fresh name
>> resolve */
>> ret = curl_easy_perform(curl);
>>
>> Thanks,
>> Narasimha
>>
>> On Tue, Sep 1, 2020 at 12:11 PM Daniel Stenberg <daniel_at_haxx.se> wrote:
>>
>>> On Tue, 1 Sep 2020, Narasimha M wrote:
>>>
>>> > Hence, I want to keep the connection and handle for a long time.
>>> However
>>> > during this time, there can be changes to the DNS server/data. I would
>>> like
>>> > the application to be agnostic to the changes to the DNS. This would
>>> have
>>> > been possible if CURL queried the DNS periodically and updated its
>>> cache for
>>> > long running handles.
>>>
>>> Sure it *could*. It's just code. It could do *anything* if we just add
>>> the
>>> code for it. This feature you're asking for has however not been
>>> implemented.
>>>
>>> > I am still not able to understand the use of CURLOPT_DNS_CACHE_TIMEOUT
>>> in
>>> > the context of a given connection which runs for a long time.
>>>
>>> curl doesn't resolve the host name AT ALL when it reuses an existing
>>> connection. It doesn't need to so it avoids it. Saves time and resources.
>>>
>>> The DNS cache is only used when a host name is resolved. If no resolving
>>> is
>>> done, the DNS cache is not used and therefore the timeout also has no
>>> meaning.
>>> The entry is since long removed from the DNS cache but the connection is
>>> still
>>> there - and working.
>>>
>>> > Could you please point me to any example which can illustrate
>>> > CURLOPT_DNS_CACHE_TIMEOUT in context of a given curl handle?
>>>
>>> How would a cache timeout even get visualized in an example? There's an
>>> example in the man page for the option:
>>> https://curl.haxx.se/libcurl/c/CURLOPT_DNS_CACHE_TIMEOUT.html
>>>
>>> --
>>>
>>> / 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.haxx.se/mail/etiquette.html
>
>
>
> --
> Saludos / Regards,
> David Requena
> -------------------------------------------------------------------
> Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
> Etiquette: https://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-09-01