Subject: bug#34196: 27.0.50; tramp hangs on wrong password with global-auto-revert-mode

From: Michael Albinus <[email-masked]>
Date: Tue, 05 Feb 2019 13:51:31 +0100

Aaron Jensen <[email-masked]> writes:

Hi Aaron,

[Pls keep the Cc, for the archives]

> I think that not-yet-connected tramp buffers need to be excluded from
> garm entirely, if that is possible.

Good idea. I've appended a patch, which reverts the last change from
tramp.el, and implements your proposal in autorevert.el. This is also
better, because Tramp as library shouldn't care about auto-revert.

Could you, pls, check whether this works for you?

> Thanks,
> Aaron

Best regards, Michael.

diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 16a742a458..150693baf1 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -767,6 +767,16 @@ auto-revert-buffers
 		    (buffer-list)
 		  auto-revert-buffer-list))
 	  remaining new)
+      ;; Buffers with remote contents shall be reverted only if the
+      ;; connection is established already.
+      (setq bufs (delq nil
+                       (mapcar
+                        (lambda (buf)
+                          (with-current-buffer buf
+                            (and (or (not (file-remote-p default-directory))
+                                     (file-remote-p default-directory nil t))
+                                 buf)))
+                        bufs)))
       ;; Partition `bufs' into two halves depending on whether or not
       ;; the buffers are in `auto-revert-remaining-buffers'.  The two
       ;; halves are then re-joined with the "remaining" buffers at the
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 82d2e5a4d3..d000bbe3d6 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -4060,23 +4060,17 @@ tramp-process-actions
   (save-restriction
     (with-tramp-progress-reporter
 	proc 3 "Waiting for prompts from remote shell"
-      ;; `global-auto-revert-mode' could activate remote operations
-      ;; while we aren't ready.  We disable it temporarily.
-      (let ((garm (bound-and-true-p global-auto-revert-mode))
-	    exit)
-	(when garm (global-auto-revert-mode -1))
-	(unwind-protect
-	    (if timeout
-		(with-timeout (timeout (setq exit 'timeout))
-		  (while (not exit)
-		    (setq exit
-			  (catch 'tramp-action
-			    (tramp-process-one-action proc vec actions)))))
+      (let (exit)
+	(if timeout
+	    (with-timeout (timeout (setq exit 'timeout))
 	      (while (not exit)
 		(setq exit
 		      (catch 'tramp-action
 			(tramp-process-one-action proc vec actions)))))
-	  (when garm (global-auto-revert-mode)))
+	  (while (not exit)
+	    (setq exit
+		  (catch 'tramp-action
+		    (tramp-process-one-action proc vec actions)))))
 	(with-current-buffer (tramp-get-connection-buffer vec)
 	  (widen)
 	  (tramp-message vec 6 "\n%s" (buffer-string)))