3

After upgrading an EC2 instance to Ubuntu 18.04 I started getting occasional errors Resolving DNS for my database server in my PHP scripts like the following:

Uncaught Exception: PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

These correlate in syslog with a restart of systemd-resolved. I turned on debug logging, but I still don't see why the service is getting restarted several times a day. Here are the syslog entries surrounding a restart:

Dec 6 11:31:20 ip-172-31-X-X systemd-resolved[15188]: Processing incoming packet on transaction 51967. (rcode=SUCCESS)
Dec 6 11:31:20 ip-172-31-X-X systemd-resolved[15188]: Processing query...
Dec 6 11:31:20 ip-172-31-X-X systemd-resolved[15188]: Cache miss for sqs.us-west-2.amazonaws.com IN A, Cache miss for sqs.us-west-2.amazonaws.com IN A @version:1 @timestamp:December 6th 2018, 05:31:20.000
Dec 6 11:31:20 ip-172-31-X-X systemd-resolved[15188]: Removing cache entry for gmail-imap.l.google.com IN AAAA (expired 19s ago)
Dec 6 11:31:22 ip-172-31-X-X systemd-resolved[15188]: Removing scope on link *, protocol dns, family *
Dec 6 11:31:22 ip-172-31-X-X dhclient[768]: DHCPREQUEST of 172.31.X.X on eth0 to 172.31.32.X port 67 (xid=0x66c614b9)
Dec 6 11:31:22 ip-172-31-X-X dhclient[768]: DHCPACK of 172.31.X.X from 172.31.32.X
Dec 6 11:31:22 ip-172-31-X-X systemd-resolved[15188]: Bus n/a: changing state RUNNING → CLOSED
Dec 6 11:31:22 ip-172-31-X-X systemd[1]: Stopping Network Name Resolution...
Dec 6 11:31:23 ip-172-31-X-X dhclient[768]: bound to 172.31.X.X -- renewal in 1565 seconds.
Dec 6 11:31:23 ip-172-31-X-X systemd-resolved[15465]: Got message type=signal sender=org.freedesktop.DBus destination=:1.2496 path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameAcquired cookie=3 reply_cookie=0 signature=s error-name=n/a error-message=n/a
Dec 6 11:31:23 ip-172-31-X-X systemd-resolved[15465]: Found new link 2/eth0
Dec 6 11:31:23 ip-172-31-X-X systemd-resolved[15465]: New scope on link *, protocol dns, family *

My /etc/resolv.conf seems to be the default AWS one and is a symlink to /run/systemd/resolve/resolv.conf which contains:

nameserver 172.31.0.X
search us-west-2.compute.internal

Anyone know why I'm getting these seemingly random restarts and what I can do to fix these?

2

for me the root cause it was systemd-resolved restarting on dhclient and from your logs I bet for you as well

have a look at this bug report https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1805183

after applying the working patch https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1805183/comments/8 php-fpm (and getaddrinfo) never complained anymore.

  • That looks very promising, thank you. I'll let you know if that works. – Michael OConnell Dec 21 '18 at 17:45
  • @MichaelOConnell did it solve your issue? If so, please accept the answer. – Arjuna Del Toso Jan 2 '19 at 17:04
1

If you have this problem, and you do not want to apply the linked patch, there is an alternative solution for the temporary DNS errors.

Disable systemd-resolved in Ubuntu. There is an explanation here, on our sister site for Ubuntu.

I will not copy the explanation here. There is already one caveat about disabling systemd-resolved. If I copy the explanation into this answer, then this answer could miss other important updates.

  • I am fairly certain this is a valid solution as well – Michael OConnell Apr 24 '19 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.