From: Madhu <enometh@meer.net>
To: emacs-devel@gnu.org
Subject: Re: Persistent failure to lookup hostname
Date: Tue, 04 Oct 2022 09:10:07 +0530 [thread overview]
Message-ID: <m3o7us45pk.fsf@leonis4.robolove.meer.net> (raw)
In-Reply-To: jwvfsg4v66f.fsf-monnier+emacs@gnu.org
[-- Attachment #1: Type: text/plain, Size: 2935 bytes --]
* Stefan Monnier <jwvfsg4v66f.fsf-monnier+emacs@gnu.org> :
Wrote on Mon, 03 Oct 2022 19:44:29 -0400:
> My Gnus session occasionally gets into a state where it insists that my
> mail server's DNS name isn't found. I haven't yet managed to get close
> to the source of the problem, in large part because I don't know how to
> reproduce it. It seems to be associated with network failures (or
> captive portals, which are basically purposefully broken networks).
>
> That a DNS lookup would fail while the network is having problem is of
> course normal, but the problem is that the failure seems to persist "for
> ever", or more specifically until I restart Emacs. E.g. the old Gnus
> sessions will keep giving me a hostname error while at the very same
> time all other processes on the system (Firefox, `host`, a fresh new
> Emacs, you name it) have no problem finding the IP address of (and even
> connecting to) the very same host.
>
> The last two times this occurred I tried to look a bit more into it, but
> I realized that I don't know enough about how this works to know where
> to look.
>
> The error itself is signaled by `make-network-process` and I suspect the
> error is actually raised by the following piece of code (tho I couldn't
> confirm it because I somehow ended up killing the process while trying to
> attach GDB to it):
>
> msg = network_lookup_address_info_1 (host, portstring, &hints, &res);
> if (!EQ (msg, Qt))
> error ("%s", SSDATA (msg));
>
> Looking at `network_lookup_address_info_1` it seems it doesn't do much
> more than call `getaddrinfo` (I couldn't copy&paste the actual error
> message but it basically contains my host name plus some error message
> in French, which seems consistent with an error message taken straight
> from `gai_strerror`).
>
> Does anyone here have an idea why `getaddrinfo` might return an outdated
> error, or whether it could come from elsewhere? Or how/where I might
> find a kind of DNS cache that would be process-local rather
> than systemwide?
* commit: commit 93bf7d52841c60ffc10e0c9c789a7987812ce55e
| Author: Paul Eggert <eggert@cs.ucla.edu>
| AuthorDate: Mon Feb 29 09:39:45 2016 -0800
| Commit: Paul Eggert <eggert@cs.ucla.edu>
| CommitDate: Mon Feb 29 09:40:58 2016 -0800
|
| Stop calling res_init
|
| Emacs shouldn’t need to call res_init any more, now that nscd or
| equivalent is everywhere. On modern systems, calling res_init simply
| slows Emacs down. On ancient systems lacking nscd Emacs will still
| work well enough with this change; it’s just that it won’t respond to
| changes in /etc/resolv.conf
Perhaps the expected results result from changes to resolv.conf, and you
aren't running glibc's nscd (I don't because it generates a lot of bogus
traffic)
The attached patch reverts that commit and reinstates res_init, maybe
you could try it to see if it helps
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: reinstate res_init --]
[-- Type: text/x-patch, Size: 4210 bytes --]
diff --git a/admin/CPP-DEFINES b/admin/CPP-DEFINES
index 06986ec8f48..a9860608076 100644
--- a/admin/CPP-DEFINES
+++ b/admin/CPP-DEFINES
@@ -236,6 +236,7 @@ HAVE_RANDOM
HAVE_READLINK
HAVE_READLINKAT
HAVE_RECVFROM
+HAVE_RES_INIT
HAVE_RINT
HAVE_RSVG
HAVE_SELECT
diff --git a/configure.ac b/configure.ac
index 4590ed3506e..38530f19ed3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5167,13 +5167,44 @@ AC_DEFUN
[emacs_cv_alternate_stack=yes],
[emacs_cv_alternate_stack=no])])
+# Do we have res_init, for detecting changes in /etc/resolv.conf?
+# On Darwin, res_init appears not to be useful: see bug#562 and
+# http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01467.html
+resolv=no
+
+if test $opsys != darwin; then
+
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>]],
+ [[return res_init();]])],
+ have_res_init=yes, have_res_init=no)
+ if test "$have_res_init" = no; then
+ OLIBS="$LIBS"
+ LIBS="$LIBS -lresolv"
+ AC_MSG_CHECKING(for res_init with -lresolv)
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>]],
+ [[return res_init();]])],
+ have_res_init=yes, have_res_init=no)
+ AC_MSG_RESULT($have_res_init)
+ if test "$have_res_init" = yes ; then
+ resolv=yes
+ fi
+ LIBS="$OLIBS"
+ fi
+
+ if test "$have_res_init" = yes; then
+ AC_DEFINE(HAVE_RES_INIT, 1, [Define to 1 if res_init is available.])
+ fi
+fi dnl !darwin
+
# Do we need the Hesiod library to provide the support routines?
dnl FIXME? Should we be skipping this on Darwin too?
LIBHESIOD=
-LIBRESOLV=
if test "$with_hesiod" != no ; then
# Don't set $LIBS here -- see comments above. FIXME which comments?
- resolv=no
AC_CHECK_FUNC([res_send], [], [AC_CHECK_FUNC([__res_send], [],
[AC_CHECK_LIB([resolv], [res_send], [resolv=yes],
[AC_CHECK_LIB([resolv], [__res_send], [resolv=yes])])])])
@@ -5189,10 +5220,16 @@ AC_DEFUN
if test x"$hesiod" = xyes; then
LIBHESIOD=-lhesiod
- LIBRESOLV=$RESOLVLIB
fi
fi
AC_SUBST([LIBHESIOD])
+
+# Do we need libresolv (due to res_init or Hesiod)?
+if test "$resolv" = yes && test $opsys != darwin; then
+ LIBRESOLV=-lresolv
+else
+ LIBRESOLV=
+fi
AC_SUBST([LIBRESOLV])
# These tell us which Kerberos-related libraries to use.
diff --git a/src/Makefile.in b/src/Makefile.in
index 1f941874ea8..e0375b43205 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -331,6 +331,9 @@ CM_OBJ=
LIBGPM = @LIBGPM@
+## -lresolv, or empty.
+LIBRESOLV = @LIBRESOLV@
+
LIBSELINUX_LIBS = @LIBSELINUX_LIBS@
LIBGNUTLS_LIBS = @LIBGNUTLS_LIBS@
@@ -559,7 +562,7 @@ LIBES =
$(LIB_EACCESS) $(LIB_TIMER_TIME) $(DBUS_LIBS) \
$(LIB_EXECINFO) $(XRANDR_LIBS) $(XINERAMA_LIBS) $(XFIXES_LIBS) \
$(XDBE_LIBS) $(XSYNC_LIBS) \
- $(LIBXML2_LIBS) $(LIBGPM) $(LIBS_SYSTEM) $(CAIRO_LIBS) \
+ $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESILV) $(LIBS_SYSTEM) $(CAIRO_LIBS) \
$(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
$(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(HARFBUZZ_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
$(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(GETADDRINFO_A_LIBS) $(LCMS2_LIBS) \
diff --git a/src/process.c b/src/process.c
index 9dfb98d8f38..8e4a27fd16b 100644
--- a/src/process.c
+++ b/src/process.c
@@ -83,6 +83,11 @@ #define HAVE_LOCAL_SOCKETS
#endif
+#ifdef HAVE_RES_INIT
+#include <arpa/nameser.h>
+#include <resolv.h>
+#endif
+
#ifdef HAVE_UTIL_H
#include <util.h>
#endif
@@ -4137,6 +4142,9 @@ DEFUN ("make-network-process", Fmake_network_process, Smake_network_process,
strcpy (req->str, SSDATA (host));
strcpy (req->str + hostlen + 1, portstring);
+#ifdef HAVE_RES_INIT
+ res_init ();
+#endif
int ret = getaddrinfo_a (GAI_NOWAIT, &dns_request, 1, NULL);
if (ret)
error ("%s/%s getaddrinfo_a error %d",
@@ -4157,6 +4165,10 @@ DEFUN ("make-network-process", Fmake_network_process, Smake_network_process,
maybe_quit ();
+#ifdef HAVE_RES_INIT
+ res_init ();
+#endif
+
struct addrinfo hints;
memset (&hints, 0, sizeof hints);
hints.ai_family = family;
next prev parent reply other threads:[~2022-10-04 3:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-03 23:44 Persistent failure to lookup hostname Stefan Monnier
2022-10-03 23:58 ` Lars Ingebrigtsen
2022-10-04 0:15 ` Stefan Monnier
2022-10-04 7:37 ` Robert Pluim
2022-10-04 8:05 ` tomas
2022-10-04 9:30 ` Robert Pluim
2022-10-04 9:40 ` tomas
2022-10-04 13:27 ` Stefan Monnier
2022-10-04 14:41 ` Robert Pluim
2022-10-04 15:07 ` Stefan Monnier
2022-10-04 3:40 ` Madhu [this message]
2022-10-04 13:20 ` Stefan Monnier
2022-10-06 19:56 ` Stefan Monnier
2022-10-14 15:53 ` Stefan Monnier
2022-10-04 6:51 ` Eli Zaretskii
2022-10-04 13:24 ` Stefan Monnier
2022-10-04 13:53 ` Eli Zaretskii
2022-10-04 14:00 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3o7us45pk.fsf@leonis4.robolove.meer.net \
--to=enometh@meer.net \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).