Issues related to stale DNS (DHCP init races)

Asked by James Shimer on 2016-04-09

I see a some old bugs hanging out which I believe are duplicates, and I believe are related to what I'm seeing in 16.04. What I've been seeing is that autofs will start before DHCP has completed and provided the correct DNS entries. When autofs goes to read the master map from LDAP getaddrinfo fails because it has stale data for the name servers which was read in when glibc was loaded (ie, when autofs first started, that is before DHCP had completed). The correct fix to this problem is to refresh the DNS resolver information prior to getaddrinfo call. This can be accomplished with res_init(). In fact it looks like this fix was already applied to lookup_hesiod.c, unfortunately it should have carried forward to similar network modules such as ldap and nis. I've patched based on wily and have been testing it. I'm putting bugs I believe related and the patch below.

Bugs I'm pretty sure are related (I believe there are actually a few more):
https://bugs.launchpad.net/ubuntu/+source/autofs/+bug/119660
https://bugs.launchpad.net/ubuntu/+source/autofs/+bug/573919

autofs/modules# diff -rupN replicated.c.orig replicated.c
--- replicated.c.orig 2016-04-08 22:57:17.329867770 -0700
+++ replicated.c 2016-04-08 23:01:04.939919189 -0700
@@ -49,6 +49,8 @@
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
 #include <netdb.h>

 #include "rpc_subs.h"
@@ -237,6 +239,7 @@ static unsigned int get_nfs_info(unsigne
  double taken = 0;
  int status, count = 0;

+ res_init();
  if (host->addr)
   debug(logopt, "called with host %s(%s) proto %d version 0x%x",
         host->name, get_addr_string(host->addr, buf, len),
@@ -898,6 +901,7 @@ static int add_host_addrs(struct host **
  int rr = 0, rr4 = 0, rr6 = 0;
  int ret;

+ res_init();
  if (!name) {
   char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
   error(LOGOPT_ANY, "strdup: %s", estr);

It's possible that I've just changed timing, but its working for me so far.

Question information

If you have reported a bug then you don't need a question as well

Can you help with this problem?

Provide an answer of your own, or ask James Shimer for more information if necessary.

To post a message you must log in.