Cache DNS queries #7379

Open
opened 2026-02-21 18:56:12 -05:00 by deekerman · 18 comments
Owner

Originally created by @tomose on GitHub (Jun 3, 2018).

qbittorrent-nox on linux

Seems like the client doesn't do any sort of caching of DNS queries at all.

Even if the caching was only for 30s at a time, it'd make for less noisy network activity.

Originally created by @tomose on GitHub (Jun 3, 2018). qbittorrent-nox on linux Seems like the client doesn't do any sort of caching of DNS queries at all. Even if the caching was only for 30s at a time, it'd make for less noisy network activity.
Author
Owner

@AGlezB commented on GitHub (Mar 18, 2020):

Also on Windows please.

Just look at NextDNS analytics for the past 7 days while seeding some 140 small torrents.
image
image

This is for the last 30 days.
image
image

And that is just the top 6.
I'm guessing qBittorrent alone ate twice over the 300K querys NextDNS intends to give for free.

@AGlezB commented on GitHub (Mar 18, 2020): Also on Windows please. Just look at NextDNS analytics for the past 7 days while seeding some 140 small torrents. ![image](https://user-images.githubusercontent.com/12277525/76925173-50ac6280-68b7-11ea-8aa6-386170e852a3.png) ![image](https://user-images.githubusercontent.com/12277525/76925346-e647f200-68b7-11ea-9750-83bb4e87f3f5.png) This is for the last 30 days. ![image](https://user-images.githubusercontent.com/12277525/76925230-818c9780-68b7-11ea-8e00-f2ff8c56f1c4.png) ![image](https://user-images.githubusercontent.com/12277525/76925328-d9c39980-68b7-11ea-85f4-8dd64da80cca.png) And that is just the top 6. I'm guessing qBittorrent alone ate twice over the 300K querys NextDNS intends to give for free.
Author
Owner

@FranciscoPombal commented on GitHub (Mar 18, 2020):

@arvidn what is libtorrent's behaviour regarding caching of DNS queries?

@FranciscoPombal commented on GitHub (Mar 18, 2020): @arvidn what is libtorrent's behaviour regarding caching of DNS queries?
Author
Owner

@arvidn commented on GitHub (Mar 18, 2020):

by default it caches DNS lookups for 1200 seconds.

https://github.com/arvidn/libtorrent/blob/RC_1_2/src/resolver.cpp#L118

I would expect operating systems would cache for at least the domain TTL as well though.

@arvidn commented on GitHub (Mar 18, 2020): by default it caches DNS lookups for 1200 seconds. https://github.com/arvidn/libtorrent/blob/RC_1_2/src/resolver.cpp#L118 I would expect operating systems would cache for at least the domain TTL as well though.
Author
Owner

@arvidn commented on GitHub (Mar 18, 2020):

@AGlezB are those counting the actual DNS request messages sent to the server? Or are they counting calls to the OS function to request a lookup?

In either case, what are the TTLs for those names? Perhaps they are configured to be re-requested frequently.

@arvidn commented on GitHub (Mar 18, 2020): @AGlezB are those counting the actual DNS request messages sent to the server? Or are they counting calls to the OS function to request a lookup? In either case, what are the TTLs for those names? Perhaps they are configured to be re-requested frequently.
Author
Owner

@AGlezB commented on GitHub (Mar 18, 2020):

@arvidn I honestly don't know.
I have NextDNS Official App installed and the screenshots come from the Analitics tab in my.nextdns.io

@AGlezB commented on GitHub (Mar 18, 2020): @arvidn I honestly don't know. I have NextDNS Official App installed and the screenshots come from the Analitics tab in my.nextdns.io
Author
Owner

@AGlezB commented on GitHub (Mar 18, 2020):

Most of those are not resolving properly which makes a lot of sense.

image

@arvidn libtorrent has any logic to prevent repeating failed queries or maybe a delay between repeats?

@AGlezB commented on GitHub (Mar 18, 2020): Most of those are not resolving properly which makes a lot of sense. ![image](https://user-images.githubusercontent.com/12277525/76974729-51bdae00-6910-11ea-934b-2756739ae70e.png) @arvidn libtorrent has any logic to prevent repeating failed queries or maybe a delay between repeats?
Author
Owner

@arvidn commented on GitHub (Mar 18, 2020):

I recently added this

@arvidn commented on GitHub (Mar 18, 2020): I recently added [this](https://github.com/arvidn/libtorrent/blob/RC_1_2/src/torrent.cpp#L11032)
Author
Owner

@tz1 commented on GitHub (May 9, 2020):

I too use NextDNS and saw a similar problem, but it is more subtle.

CACHING WILL NOT FIX THIS

NextDNS does NOT distinguish failed DNS requests from actually resolved ones.

The problem is the excess queries are a few seconds apart and happen when the lookup FAILS.

It seems to be instantly retried, often dozens of times without any backoff. There are several in my list, and when I manually check with nslookup, I don't get the "blocked", I get "doesn't exist", and from many DNS servers.

So if there is a failure looking up a tracker by DNS, it should mark it as not working and/or try maybe after a few seconds, then after a longer period (moving cables, router reboot), then timeout for another hour or so.

It also appears if there are several active torrents with the same unresolvable tracker, they will ALL try the DNS entry, so caching would help this as well since I often see multiple queries for the SAME tracker less than a second apart, and the TTLs can't be that small on the entry.

I was looking in the code, but didn't find where it is looking up the tracker DNS entry, and there is a lot of code.

@tz1 commented on GitHub (May 9, 2020): I too use NextDNS and saw a similar problem, but it is more subtle. CACHING WILL NOT FIX THIS NextDNS does NOT distinguish failed DNS requests from actually resolved ones. The problem is the excess queries are a few seconds apart and happen when the lookup FAILS. It seems to be instantly retried, often dozens of times without any backoff. There are several in my list, and when I manually check with nslookup, I don't get the "blocked", I get "doesn't exist", and from many DNS servers. So if there is a failure looking up a tracker by DNS, it should mark it as not working and/or try maybe after a few seconds, then after a longer period (moving cables, router reboot), then timeout for another hour or so. It also appears if there are several active torrents with the same unresolvable tracker, they will ALL try the DNS entry, so caching would help this as well since I often see multiple queries for the SAME tracker less than a second apart, and the TTLs can't be that small on the entry. I was looking in the code, but didn't find where it is looking up the tracker DNS entry, and there is a lot of code.
Author
Owner

@arvidn commented on GitHub (May 9, 2020):

The host name lookups happen via a class libtorrent/resolver.hpp which does some caching. The underlying primitive of performing lookups goes through boost.asio's resolver though, which has each platform specific call to perform lookups.

Is it really the case that operating systems don't cache DNS requests? It would seem quite natural for them to do so, they even have the TTL.

@arvidn commented on GitHub (May 9, 2020): The host name lookups happen via a class `libtorrent/resolver.hpp` which does some caching. The underlying primitive of performing lookups goes through boost.asio's resolver though, which has each platform specific call to perform lookups. Is it really the case that operating systems don't cache DNS requests? It would seem quite natural for them to do so, they even have the TTL.
Author
Owner

@AGlezB commented on GitHub (May 9, 2020):

Windows has a DNS Cache service but maybe libtorrent is bypassing it.

@AGlezB commented on GitHub (May 9, 2020): Windows has a DNS Cache service but maybe libtorrent is bypassing it.
Author
Owner

@tz1 commented on GitHub (May 9, 2020):

Operating systems generally do NOT cache requests unless the DNS "server" is running on the OS. Normally they simply forward requests upstream to that specified in the DHCP entry for DNS, typically the router. The router itself may or may not cache, and a problem is that most that forward to NextDNS (the program) do NOT cache replies, and the NextDNS app doesn't cache.

The other problem is nothing I know of caches the "doesn't exist" response, only the resolved IP address. So the large blob of tries for unresolavable domains will always result in attempts.

Maybe I need to look into libtorrent since it isn't in the tree.

@tz1 commented on GitHub (May 9, 2020): Operating systems generally do NOT cache requests unless the DNS "server" is running on the OS. Normally they simply forward requests upstream to that specified in the DHCP entry for DNS, typically the router. The router itself may or may not cache, and a problem is that most that forward to NextDNS (the program) do NOT cache replies, and the NextDNS app doesn't cache. The other problem is nothing I know of caches the "doesn't exist" response, only the resolved IP address. So the large blob of tries for unresolavable domains will always result in attempts. Maybe I need to look into libtorrent since it isn't in the tree.
Author
Owner

@tz1 commented on GitHub (May 9, 2020):

to clarify, "gethostbyname()" doesn't cache. A local DNS server that forwards requests generally does when it gets a valid response (and for the TTL duraton).

@tz1 commented on GitHub (May 9, 2020): to clarify, "gethostbyname()" doesn't cache. A local DNS server that forwards requests generally does when it gets a valid response (and for the TTL duraton).
Author
Owner

@farid-fari commented on GitHub (May 11, 2020):

@tz1 I don't think the issue about failing requests is the main issue at hand, it's probably a separate issue you can open. In my case, every tracker is resolved correctly, yet qBittorrent makes a DNS request per torrent. It makes them all nearly simultaneously, meaning that it's not waiting to cache results.

So I do think that caching would solve this, you just need to be clever about the way you do it -- maybe ping a tracker once and only once you've cached the DNS result make further requests to it.

This is a necessary feature though, every major piece of software has to go through this if it's doing this many DNS requests, it's incredibly wasteful as is right now.

Edit: my temporary fix is resolving these and putting them in /etc/hosts but clearly, not a long-term solution.

@farid-fari commented on GitHub (May 11, 2020): @tz1 I don't think the issue about failing requests is the main issue at hand, it's probably a separate issue you can open. In my case, every tracker is resolved correctly, yet qBittorrent makes a DNS request per torrent. It makes them all nearly simultaneously, meaning that it's not waiting to cache results. So I do think that caching would solve this, you just need to be clever about the way you do it -- maybe ping a tracker once and only once you've cached the DNS result make further requests to it. This is a necessary feature though, every major piece of software has to go through this if it's doing this many DNS requests, it's incredibly wasteful as is right now. Edit: my temporary fix is resolving these and putting them in `/etc/hosts` but clearly, not a long-term solution.
Author
Owner

@crackwitz commented on GitHub (Nov 4, 2020):

I'm running v4.3.0.1 on windows and I notice some CPU load from the "Dnscache" service of Windows (svchost), that goes away as soon as I close qB. it is not changed by enabling or disabling "Advanced > Resolve peer host names" so my suspicion is that it's related to trackers. I have ~200 "resumed" torrents, some of which surely have trackers that aren't there anymore.

I'd really like to get this CPU load taken care of. this wasn't an issue on qB v3.3 and whatever libtorrent version was used back then.

@crackwitz commented on GitHub (Nov 4, 2020): I'm running v4.3.0.1 on windows and I notice some CPU load from the "Dnscache" service of Windows (svchost), that goes away as soon as I close qB. it is not changed by enabling or disabling "Advanced > Resolve peer host names" so my suspicion is that it's related to trackers. I have ~200 "resumed" torrents, some of which surely have trackers that aren't there anymore. I'd really like to get this CPU load taken care of. this wasn't an issue on qB v3.3 and whatever libtorrent version was used back then.
Author
Owner

@nasbdh9 commented on GitHub (Apr 7, 2023):

dns returns an unavailable CDN IP, so it takes 20 minutes to refresh again?
What needs to be set to disable these caches?

@nasbdh9 commented on GitHub (Apr 7, 2023): dns returns an unavailable CDN IP, so it takes 20 minutes to refresh again? What needs to be set to disable these caches?
Author
Owner

@arvidn commented on GitHub (Apr 8, 2023):

I'm experimenting with this: https://github.com/arvidn/libtorrent/pull/7373

@arvidn commented on GitHub (Apr 8, 2023): I'm experimenting with this: https://github.com/arvidn/libtorrent/pull/7373
Author
Owner

@luzpaz commented on GitHub (Mar 15, 2025):

See also #22439

@luzpaz commented on GitHub (Mar 15, 2025): See also #22439
Author
Owner

@xavier2k6 commented on GitHub (May 23, 2025):

ANNOUNCEMENT!

For anybody coming across this "Feature Request" & would like/love to see a potential implementation in the future!
Here are some options available to you:

  1. Please select/click the 👍 &/orreactions in the original/opening post of this ticket.

  2. Please feel free (If you have the "skillset") to create a "Pull Request" implementing what's being requested in this ticket.
    (new/existing contributors/developers are always welcome)


DO:

  • Provide constructive feedback.
  • Display how other projects implemented same/similar etc.

DO NOT:

  • Add a "Bump", "me too", "2nd/3rd" etc. or "criticizing" comment(s).
    (These will be disregarded/hidden as "spam/abuse/off-topic" etc. as they don't provide anything constructive.)
@xavier2k6 commented on GitHub (May 23, 2025): ## ANNOUNCEMENT! For anybody coming across this **_"Feature Request"_** & would like/love to see a potential implementation in the future! **Here are some options available to you:** 1. Please select/click the 👍 **&/or** ❤ `reactions` in the original/opening post of this ticket. 2. Please feel free _(If you have the "skillset")_ to create a **_"Pull Request"_** implementing what's being requested in this ticket. **_(new/existing contributors/developers are always welcome)_** ____ **DO:** * Provide constructive feedback. * Display how other projects implemented same/similar etc. **DO NOT:** * Add a "Bump", "me too", "2nd/3rd" etc. or "criticizing" comment(s). **(These will be disregarded/hidden as "spam/abuse/off-topic" etc. as they don't provide anything constructive.)**
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/qBittorrent#7379
No description provided.