Michael Albinus <[email protected]> writes:

Hi,

>> I suspect that the problem may be triggered by Tramp's session timeout, as I 
>> am seeing this message in the *Messages* window:
>>
>> Tramp: Timeout session /sudo:root@hostname:
>>
>> I fear that, after the session times out, Tramp gets confused about the 
>> previous lock file upon reconnection, and gets confused with the temporary 
>> file when saving, so that it leaves one of them behind.
>
> Good catch! I'll see what I can do. One idea is, that a session timeout
> is suppressed as long as there are modified buffers visiting a respective
> remote file.
>
>> If you edit a file, but do not save it, I am not sure that it is such a good 
>> idea for Tramp to let the connection timeout, especially if a lock file has 
>> been created.
>
> Indeed, see my comment above.

I've prepared a patch, see appended. It is on top of Tramp 2.8.0.1 from
GNU ELPA, which you must install first. Could you, pls, check?

>> Thanks in advance,
>>   rdiez

Best regards, Michael.

diff --git a/lisp/tramp-sh.el b/lisp/tramp-sh.el
index 3c1f36fa..ca8f5b88 100644
--- a/lisp/tramp-sh.el
+++ b/lisp/tramp-sh.el
@@ -5154,17 +5154,27 @@ Goes through the list `tramp-inline-compress-commands'."
 ;;;###tramp-autoload
 (defun tramp-timeout-session (vec)
   "Close the connection VEC after a session timeout.
-If there is just some editing, retry it after 5 seconds."
-  (if (and (tramp-get-connection-property
-	    (tramp-get-connection-process vec) "locked")
-	   (tramp-file-name-equal-p vec (car tramp-current-connection)))
-      (progn
-	(tramp-message
-	 vec 5 "Cannot timeout session, trying it again in %s seconds." 5)
-	(run-at-time 5 nil #'tramp-timeout-session vec))
+If there is just some editing, retry it after 5 seconds.
+If there is a odified buffer, suppress it."
+  (cond
+   ((and (tramp-get-connection-property
+	  (tramp-get-connection-process vec) "locked")
+	 (tramp-file-name-equal-p vec (car tramp-current-connection)))
     (tramp-message
-     vec 3 "Timeout session %s" (tramp-make-tramp-file-name vec 'noloc))
-    (tramp-cleanup-connection vec 'keep-debug nil 'keep-processes)))
+     vec 5 "Cannot timeout session, trying it again in %s seconds." 5)
+    (run-at-time 5 nil #'tramp-timeout-session vec))
+   ((seq-some
+     (lambda (buf)
+       (and-let*
+	   (((buffer-modified-p buf))
+	    (bfn (buffer-file-name buf))
+	    (v (tramp-ensure-dissected-file-name bfn))
+	    ((tramp-file-name-equal-p vec v)))))
+     (tramp-list-remote-buffers))
+    (tramp-message vec 5 "Cannot timeout session (modified buffer)."))
+   (t (tramp-message
+       vec 3 "Timeout session %s" (tramp-make-tramp-file-name vec 'noloc))
+      (tramp-cleanup-connection vec 'keep-debug nil 'keep-processes))))
 
 (defun tramp-maybe-open-connection (vec)
   "Maybe open a connection VEC.

Reply via email to