Subject: bug#45518: Ctrl-G Fails to Interrupt Hung Tramp Remote-Compile in Emacs 27.1

From: Michael Albinus <[email-masked]>
Date: Thu, 11 Feb 2021 16:22:26 +0100

Michael Albinus <[email-masked]> writes:

Hi Duncan,

>> There is still one tramp hanging issue I saw in my testing. This is a
>> much less serious issue (pressing ctrl-G once "unhangs"), but thought
>> I'd mention it here. LMK if you'd prefer a separate bug report and
>> I'll create one.
>
> Just an update. I've played with this for a while. I could reproduce,
> and I also know where it hangs. It is accept-process-output of the Tramp
> process which tries to view the file you have clicked on, vs
> accept-process-output of the compile process. Both don't cooperate
> sufficiently, and both hang.
>
> I have no idea (yet) how to solve. One idea would be to start the
> compilation process in another thread, but this will raise other
> problems. There is some WIP to make Tramp thread-safe, but this is
> stalled ATM.

Since I don't know a general solution yet, I have prepared a small
patch, which suppresses visting remote files as result of a
compilation. Silently. When compilation has finished, everything is back
to normal.

See the appended patch, whether it makes the situation better for you.

>> Thanks again for fixing the main hanging issue!
>> Duncan.

Best regards, Michael.

*** /tmp/ediffuS9ebt	2021-02-11 16:14:54.793873579 +0100
--- /net/ford/albinus/src/tramp/lisp/tramp-integration.el	2021-02-11 16:10:01.276681568 +0100
***************
*** 261,266 ****
--- 261,294 ----
  		  (delete (info-lookup->mode-cache 'symbol ',mode)
  			  (info-lookup->topic-cache 'symbol))))))))

+ ;; Compilation processes use `accept-process-output' such a way that
+ ;; Tramp's parallel `accept-process-output' blocks.  See last part of
+ ;; Bug#45518.  So we forbid them to run in parallel.  There must be a
+ ;; better solution, though.
+ (with-eval-after-load 'compile
+   (add-hook 'compilation-start-hook
+ 	    #'tramp-compile-advice-add)
+   (add-hook 'compilation-finish-functions
+ 	    #'tramp-compile-advice-remove)
+   (add-hook 'tramp-integration-unload-hook
+ 	    (lambda ()
+ 	      (remove-hook 'compilation-start-hook
+ 			   #'tramp-compile-advice-add)
+ 	      (remove-hook 'compilation-finish-functions
+ 			   #'tramp-compile-advice-remove))))
+
+ (defun tramp-compile-advice-add (proc)
+   "Don't allow remote file operations while compiling."
+   (with-current-buffer (process-buffer proc)
+     (when (file-remote-p default-directory)
+       (advice-add 'ignore :override 'compile-goto-error))))
+
+ (defun tramp-compile-advice-remove (buffer _message)
+   "Reenable remote file operations."
+   (with-current-buffer buffer
+     (when (file-remote-p  default-directory)
+       (advice-remove 'ignore 'compile-goto-error))))
+
  ;;; Default connection-local variables for Tramp:
  ;; `connection-local-set-profile-variables' and
  ;; `connection-local-set-profiles' exists since Emacs 26.1.