You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
systemd-resolve hits watchdog timeout when /etc/hosts contains many entries #9718
I don't think #9742 should be considered a "fix"...
I am not sure the usecase is particularly valid (I mean, who does this?). That said, work on optimizing this certainly would be welcome.
Does nss-files actually work better for this kind of stuff? I somehow doubt that, given that on each and every single lookup it will parse and iterate through the file again and again
I looked into this. On top of @yuwata's cleanups, I made the storing of "blacklist" entries slightly more efficient, so that here reading of hosts with ~1.3e6 entries takes less time and uses less memory (about 25% less).
In effect, reading of /etc/hosts is about 3 times slower than a libnss_files.so.2 query for a filename at the end of file (which forces the reading of the whole file). In our code, a lot of time is spent in the parsing functions:
dns_label_unescape is indeed not very efficient. I tried to make it faster, but it just does a lot of unaligned memory accesses and comparisons, and I don't see a way to make it significantly faster without complicating things a lot. Apart from that we do a lot of small memory allocations and comparisons, which is slow too.
Nevertheless, I think being 3 times slower than a simple function which flies through the file in a tight loop is acceptable. I expect allocating storage and copying all the data in bits should take at least as much time as simply reading the file, and we're not much slower than that. systemd-resolved could probably be made more memory-efficient by using a trie structure for the blacklisted strings. But having such a large hosts file is something of a special case, and I think our level of support is adequate. If somebody cares about this use case, they can work on the code and file a PR.
--
The original report suggests that resolved keeps reading the file. But it should read the file just once, and then should never read it again until it is modified. So with libnss_files each lookup takes e.g. 1.5s, and with libnss_resolve the first lookup takes 5s, and all subsequent ones are "instantaneous". @rpost do you see something different?
But it should read the file just once, and then should never read it again until it is modified.
I ran host google.com and waited until cpu is calm again (took 3 minutes) - I assume it finished reading hosts file. Unfortunately this doesn't helped: running host command again resulted with timeout as well (and cpu running at 100% for 2 mins this time).
So with libnss_files each lookup takes e.g. 1.5s, and with libnss_resolve the first lookup takes 5s, and all subsequent ones are "instantaneous".
I'm sorry but I don't know what this libnss stuff is. If you are asking me how it was behaving before I started using systemd-resolve (reads: on my Mint 18.3) then each name resolution took about 0.5 sec (for the names present in hosts file)
Running host google.com would completely bypass the /etc/hosts file without a resolv.conf entry pointed at 127.0.0.53. That's probably why it resolves so quickly.
Could you try running getent hosts google.com on a system that doesn't use systemd-resolved? It will probably be much slower than the host command.
radek@t550 ~ $ time getent hosts google.com
2a00:1450:401b:806::200e google.com
real 0m0.219s
user 0m0.208s
sys 0m0.008s
radek@t550 ~ $ time getent hosts 0-0-0-0-0-0-0-0-0-0-0-0-0-16-0-0-0-0-0-0-0-0-0-0-0-0-0.info #sample host from hosts file
127.0.0.1 0-0-0-0-0-0-0-0-0-0-0-0-0-16-0-0-0-0-0-0-0-0-0-0-0-0-0.info
real 0m0.639s
user 0m0.521s
sys 0m0.017s
Please attach your /etc/hosts file too if possible and output of journalctl -bu systemd-resolved.
I ran host google.com and waited until cpu is calm again (took 3 minutes) - I assume it finished reading hosts file. Unfortunately this doesn't helped: running host command again resulted with timeout as well (and cpu running at 100% for 2 mins this time).
systemd-resolved.service has a watchdog timeout of 3 minutes. So it's possible that resolved gets killed by the watchdog, repeatedly. This would explain the original report of constant cpu utilization.
FWIW, I tested a resolved lookup with that million entry hosts file, and got a result back in around 5 seconds on the first query, and less than a second on subsequent queries. I wasn't able to reproduce the multi-minute delay.
$ cat /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53
$ cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.
passwd: compat systemd
group: compat systemd
shadow: compat
gshadow: files
hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
$ journalctl -b -u systemd-resolved
-- Logs begin at Wed 2018-07-25 21:09:05 CEST, end at Thu 2018-08-02 22:30:06 CEST. --
Aug 02 22:16:06 radek-VirtualBox systemd[1]: Starting Network Name Resolution...
Aug 02 22:16:06 radek-VirtualBox systemd-resolved[359]: Positive Trust Anchors:
Aug 02 22:16:06 radek-VirtualBox systemd-resolved[359]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5
Aug 02 22:16:06 radek-VirtualBox systemd-resolved[359]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Aug 02 22:16:06 radek-VirtualBox systemd-resolved[359]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172.in-addr.arpa 24.172.in-addr.arpa 25.172.in-addr.arpa 26.172.in-addr.arpa 27.172.in-addr.arpa 28.172.in-addr.arpa 29.172.in-addr.arpa 30.172.in-addr.arpa 31.172.in-addr.arpa 168.192.in-addr.arpa d.f.ip6.arpa corp home internal intranet lan local private test
Aug 02 22:16:06 radek-VirtualBox systemd-resolved[359]: Using system hostname 'radek-VirtualBox'.
Aug 02 22:16:06 radek-VirtualBox systemd[1]: Started Network Name Resolution.
Aug 02 22:19:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Watchdog timeout (limit 3min)!
Aug 02 22:19:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Killing process 359 (systemd-resolve) with signal SIGABRT.
Aug 02 22:19:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Main process exited, code=dumped, status=6/ABRT
Aug 02 22:19:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Failed with result 'watchdog'.
Aug 02 22:19:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Service has no hold-off time, scheduling restart.
Aug 02 22:19:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Scheduled restart job, restart counter is at 1.
Aug 02 22:19:06 radek-VirtualBox systemd[1]: Stopped Network Name Resolution.
Aug 02 22:19:06 radek-VirtualBox systemd[1]: Starting Network Name Resolution...
Aug 02 22:19:06 radek-VirtualBox systemd-resolved[1951]: Positive Trust Anchors:
Aug 02 22:19:06 radek-VirtualBox systemd-resolved[1951]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5
Aug 02 22:19:06 radek-VirtualBox systemd-resolved[1951]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Aug 02 22:19:06 radek-VirtualBox systemd-resolved[1951]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172.in-addr.arpa 24.172.in-addr.arpa 25.172.in-addr.arpa 26.172.in-addr.arpa 27.172.in-addr.arpa 28.172.in-addr.arpa 29.172.in-addr.arpa 30.172.in-addr.arpa 31.172.in-addr.arpa 168.192.in-addr.arpa d.f.ip6.arpa corp home internal intranet lan local private test
Aug 02 22:19:06 radek-VirtualBox systemd-resolved[1951]: Using system hostname 'radek-VirtualBox'.
Aug 02 22:19:06 radek-VirtualBox systemd[1]: Started Network Name Resolution.
Aug 02 22:22:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Watchdog timeout (limit 3min)!
Aug 02 22:22:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Killing process 1951 (systemd-resolve) with signal SIGABRT.
Aug 02 22:22:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Main process exited, code=dumped, status=6/ABRT
Aug 02 22:22:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Failed with result 'watchdog'.
Aug 02 22:22:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Service has no hold-off time, scheduling restart.
Aug 02 22:22:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Scheduled restart job, restart counter is at 2.
Aug 02 22:22:06 radek-VirtualBox systemd[1]: Stopped Network Name Resolution.
Aug 02 22:22:06 radek-VirtualBox systemd[1]: Starting Network Name Resolution...
Aug 02 22:22:06 radek-VirtualBox systemd-resolved[2348]: Positive Trust Anchors:
Aug 02 22:22:06 radek-VirtualBox systemd-resolved[2348]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5
Aug 02 22:22:06 radek-VirtualBox systemd-resolved[2348]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Aug 02 22:22:06 radek-VirtualBox systemd-resolved[2348]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172.in-addr.arpa 24.172.in-addr.arpa 25.172.in-addr.arpa 26.172.in-addr.arpa 27.172.in-addr.arpa 28.172.in-addr.arpa 29.172.in-addr.arpa 30.172.in-addr.arpa 31.172.in-addr.arpa 168.192.in-addr.arpa d.f.ip6.arpa corp home internal intranet lan local private test
Aug 02 22:22:06 radek-VirtualBox systemd-resolved[2348]: Using system hostname 'radek-VirtualBox'.
Aug 02 22:22:06 radek-VirtualBox systemd[1]: Started Network Name Resolution.
Aug 02 22:25:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Watchdog timeout (limit 3min)!
Aug 02 22:25:06 radek-VirtualBox systemd[1]: systemd-resolved.service: Killing process 2348 (systemd-resolve) with signal SIGABRT.
Aug 02 22:25:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Main process exited, code=dumped, status=6/ABRT
Aug 02 22:25:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Failed with result 'watchdog'.
Aug 02 22:25:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Service has no hold-off time, scheduling restart.
Aug 02 22:25:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Scheduled restart job, restart counter is at 3.
Aug 02 22:25:07 radek-VirtualBox systemd[1]: Stopped Network Name Resolution.
Aug 02 22:25:07 radek-VirtualBox systemd[1]: Starting Network Name Resolution...
Aug 02 22:25:07 radek-VirtualBox systemd-resolved[2386]: Positive Trust Anchors:
Aug 02 22:25:07 radek-VirtualBox systemd-resolved[2386]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5
Aug 02 22:25:07 radek-VirtualBox systemd-resolved[2386]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Aug 02 22:25:07 radek-VirtualBox systemd-resolved[2386]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172.in-addr.arpa 24.172.in-addr.arpa 25.172.in-addr.arpa 26.172.in-addr.arpa 27.172.in-addr.arpa 28.172.in-addr.arpa 29.172.in-addr.arpa 30.172.in-addr.arpa 31.172.in-addr.arpa 168.192.in-addr.arpa d.f.ip6.arpa corp home internal intranet lan local private test
Aug 02 22:25:07 radek-VirtualBox systemd-resolved[2386]: Using system hostname 'radek-VirtualBox'.
Aug 02 22:25:07 radek-VirtualBox systemd[1]: Started Network Name Resolution.
Aug 02 22:28:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Watchdog timeout (limit 3min)!
Aug 02 22:28:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Killing process 2386 (systemd-resolve) with signal SIGABRT.
Aug 02 22:28:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Main process exited, code=dumped, status=6/ABRT
Aug 02 22:28:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Failed with result 'watchdog'.
Aug 02 22:28:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Service has no hold-off time, scheduling restart.
Aug 02 22:28:07 radek-VirtualBox systemd[1]: systemd-resolved.service: Scheduled restart job, restart counter is at 4.
Aug 02 22:28:07 radek-VirtualBox systemd[1]: Stopped Network Name Resolution.
Aug 02 22:28:07 radek-VirtualBox systemd[1]: Starting Network Name Resolution...
Aug 02 22:28:07 radek-VirtualBox systemd-resolved[2449]: Positive Trust Anchors:
Aug 02 22:28:07 radek-VirtualBox systemd-resolved[2449]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5
Aug 02 22:28:07 radek-VirtualBox systemd-resolved[2449]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Aug 02 22:28:07 radek-VirtualBox systemd-resolved[2449]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172.in-addr.arpa 24.172.in-addr.arpa 25.172.in-addr.arpa 26.172.in-addr.arpa 27.172.in-addr.arpa 28.172.in-addr.arpa 29.172.in-addr.arpa 30.172.in-addr.arpa 31.172.in-addr.arpa 168.192.in-addr.arpa d.f.ip6.arpa corp home internal intranet lan local private test
Aug 02 22:28:07 radek-VirtualBox systemd-resolved[2449]: Using system hostname 'radek-VirtualBox'.
Aug 02 22:28:07 radek-VirtualBox systemd[1]: Started Network Name Resolution.
changed the title [-]systemd-resolve hangs when /etc/hosts contains many entries[/-][+]systemd-resolve hits watchdog timeout when /etc/hosts contains many entries[/+]on Nov 15, 2018
It seems that @rpost's system is just very very slow. On my machine, with git master it takes about 4s to read the long /etc/hosts file. Even if the system was 10 times slower, that still only 40 s, and the timeout is 180 s. So maybe it's not just slow, but something else is going on.
Activity
yuwata commentedon Jul 26, 2018
Wow...
filbranden commentedon Jul 26, 2018
Well, for a while there, this was a somewhat common practice... I hoped these times were behind us now... maybe?
yuwata commentedon Jul 26, 2018
I've confirmed this with the hosts file provided in the above link...
yuwata commentedon Jul 26, 2018
A workaround for this is adding an option to toggle reading /etc/hosts in resolved.conf, e.g.,
ReadEtcHosts=[BOOL]. What do you think?yuwata commentedon Jul 26, 2018
Hmm... With 100000 lines of a blacklist /etc/hosts,
manager_etc_hosts_read().manager_etc_hosts_read()with commenting outhashmap_put()inadd_item().yuwata commentedon Jul 28, 2018
I am not sure whether it is a appropriate way or not, but introduced a workaround for this in #9742.
resolve: add option to toggle reading /etc/hosts
poettering commentedon Jul 30, 2018
I don't think #9742 should be considered a "fix"...
I am not sure the usecase is particularly valid (I mean, who does this?). That said, work on optimizing this certainly would be welcome.
Does nss-files actually work better for this kind of stuff? I somehow doubt that, given that on each and every single lookup it will parse and iterate through the file again and again
keszybz commentedon Aug 1, 2018
I looked into this. On top of @yuwata's cleanups, I made the storing of "blacklist" entries slightly more efficient, so that here reading of hosts with ~1.3e6 entries takes less time and uses less memory (about 25% less).
In effect, reading of
/etc/hostsis about 3 times slower than alibnss_files.so.2query for a filename at the end of file (which forces the reading of the whole file). In our code, a lot of time is spent in the parsing functions:dns_label_unescapeis indeed not very efficient. I tried to make it faster, but it just does a lot of unaligned memory accesses and comparisons, and I don't see a way to make it significantly faster without complicating things a lot. Apart from that we do a lot of small memory allocations and comparisons, which is slow too.Nevertheless, I think being 3 times slower than a simple function which flies through the file in a tight loop is acceptable. I expect allocating storage and copying all the data in bits should take at least as much time as simply reading the file, and we're not much slower than that.
systemd-resolvedcould probably be made more memory-efficient by using a trie structure for the blacklisted strings. But having such a large hosts file is something of a special case, and I think our level of support is adequate. If somebody cares about this use case, they can work on the code and file a PR.--
The original report suggests that resolved keeps reading the file. But it should read the file just once, and then should never read it again until it is modified. So with libnss_files each lookup takes e.g. 1.5s, and with libnss_resolve the first lookup takes 5s, and all subsequent ones are "instantaneous". @rpost do you see something different?
rpost commentedon Aug 1, 2018
I ran
host google.comand waited until cpu is calm again (took 3 minutes) - I assume it finished reading hosts file. Unfortunately this doesn't helped: running host command again resulted with timeout as well (and cpu running at 100% for 2 mins this time).I'm sorry but I don't know what this libnss stuff is. If you are asking me how it was behaving before I started using systemd-resolve (reads: on my Mint 18.3) then each name resolution took about 0.5 sec (for the names present in hosts file)
floppym commentedon Aug 1, 2018
Running
host google.comwould completely bypass the /etc/hosts file without a resolv.conf entry pointed at 127.0.0.53. That's probably why it resolves so quickly.Could you try running
getent hosts google.comon a system that doesn't use systemd-resolved? It will probably be much slower than thehostcommand.rpost commentedon Aug 1, 2018
yuwata commentedon Aug 2, 2018
@rpost Could you paste /etc/resolv.conf and /etc/nsswitch.conf ?
keszybz commentedon Aug 2, 2018
Please attach your
/etc/hostsfile too if possible and output ofjournalctl -bu systemd-resolved.systemd-resolved.service has a watchdog timeout of 3 minutes. So it's possible that resolved gets killed by the watchdog, repeatedly. This would explain the original report of constant cpu utilization.
floppym commentedon Aug 2, 2018
FWIW, I tested a resolved lookup with that million entry hosts file, and got a result back in around 5 seconds on the first query, and less than a second on subsequent queries. I wasn't able to reproduce the multi-minute delay.
rpost commentedon Aug 2, 2018
Indeed:
systemd[1]: systemd-resolved.service: Watchdog timeout (limit 3min)!. hosts.zip attached.allen-munsch commentedon Nov 14, 2018
fwiw : being inspired by https://github.com/pi-hole/pi-hole
I have also attempted a huge blacklist/whitelist using systemd, but have yet to find a solution using systemd-resolved
For more context on the particulars of what I had attempted : https://unix.stackexchange.com/questions/479600/systemd-resolved-block-a-domain-name
[-]systemd-resolve hangs when /etc/hosts contains many entries[/-][+]systemd-resolve hits watchdog timeout when /etc/hosts contains many entries[/+]keszybz commentedon Nov 15, 2018
It seems that @rpost's system is just very very slow. On my machine, with git master it takes about 4s to read the long /etc/hosts file. Even if the system was 10 times slower, that still only 40 s, and the timeout is 180 s. So maybe it's not just slow, but something else is going on.
@rpost: what if you add
Does this solve the issue?
poettering commentedon Jul 10, 2019
Let's close this for now, as optimizations have been added, and there hasn't been a reply in a long time.