emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 934dcc2 1/2: Fix hang when running dns-query with no working inte


From: Robert Pluim
Subject: master 934dcc2 1/2: Fix hang when running dns-query with no working internet
Date: Mon, 22 Feb 2021 09:49:13 -0500 (EST)

branch: master
commit 934dcc21572e3f0e5357d84050e04b23d41a18f9
Author: Robert Pluim <rpluim@gmail.com>
Commit: Robert Pluim <rpluim@gmail.com>

    Fix hang when running dns-query with no working internet
    
    * lisp/net/dns.el (dns-set-servers): reduce the timeout and retry
    count when using 'nslookup' for "localhost".
    (dns-query): Check to see if we actually managed to initiate a dns
    request before starting a busy-wait for the result.
---
 lisp/net/dns.el | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lisp/net/dns.el b/lisp/net/dns.el
index 2045d4d..90776e3 100644
--- a/lisp/net/dns.el
+++ b/lisp/net/dns.el
@@ -332,7 +332,7 @@ Parses \"/etc/resolv.conf\" or calls \"nslookup\"."
          (setq dns-servers (nreverse dns-servers))))
       (when (executable-find "nslookup")
        (with-temp-buffer
-         (call-process "nslookup" nil t nil "localhost")
+         (call-process "nslookup" nil t nil "-retry=0" "-timeout=2" 
"localhost")
          (goto-char (point-min))
           (when (re-search-forward
           "^Address:[ 
\t]*\\([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\|[[:xdigit:]:]*\\)" nil t)
@@ -492,19 +492,22 @@ If REVERSE, look up an IP address."
                            (dns-get-txt-answer (dns-get 'answers result))
                          (dns-get 'data answer))))))))))
 
+;;;###autoload
 (defun dns-query (name &optional type full reverse)
   "Query a DNS server for NAME of TYPE.
 If FULL, return the entire record returned.
 If REVERSE, look up an IP address."
-  (let ((result nil))
-    (dns-query-asynchronous
-     name
-     (lambda (response)
-       (setq result (list response)))
-     type full reverse)
-    ;; Loop until we get the callback.
-    (while (not result)
-      (sleep-for 0.01))
+  (let* ((result nil)
+         (query-started
+          (dns-query-asynchronous
+           name
+           (lambda (response)
+             (setq result (list response)))
+           type full reverse)))
+    (if query-started
+        ;; Loop until we get the callback.
+        (while (not result)
+          (sleep-for 0.01)))
     (car result)))
 
 (provide 'dns)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]