1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

Suppress Tramp session timeout if buffer is modified

* doc/misc/tramp.texi (Predefined connection information): A session
timeout is suppressed if there is a modified buffer, or a buffer
under auto-revert.
(Traces and Profiles): Tramp messages are written to the *Messages*
buffer when level is less than or equal to 3.

* lisp/net/tramp-sh.el (tramp-timeout-session): Do not timeout
when buffer is modified, or in auto-revert mode.

* test/lisp/net/tramp-tests.el (tramp-test48-session-timeout):
Extend test.
This commit is contained in:
Michael Albinus 2025-08-17 11:19:01 +02:00
parent 23b766b503
commit 6979bce0b2
3 changed files with 72 additions and 15 deletions

View file

@ -2376,9 +2376,11 @@ value is @t{"-l"}, but some shells, like @command{ksh}, prefer
All @file{tramp-sh.el} based methods accept the property
@t{"session-timeout"}. This is the time (in seconds) after a
connection is disabled for security reasons, and must be
reestablished. A value of @code{nil} disables this feature. Most of
the methods do not set this property except the @option{sudo},
@option{doas} and @option{run0} methods, which use predefined values.
reestablished@footnote{If there is a modified buffer, or a buffer
under @code{auto-revert}, this is suppressed.}. A value of @code{nil}
disables this feature. Most of the methods do not set this property
except the @option{sudo}, @option{doas} and @option{run0} methods,
which use predefined values.
@item @t{"~"}@*
@t{"~user"}
@ -6834,7 +6836,8 @@ they are kept. Example:
@value{tramp} messages are raised with verbosity levels ranging from 0
to 10. @value{tramp} does not display all messages; only those with a
verbosity level less than or equal to @code{tramp-verbose}.
verbosity level less than or equal to 3, when @code{tramp-verbose}
permits.
@noindent
The verbosity levels are

View file

@ -5154,17 +5154,41 @@ 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
If there is just some editing, retry it after 5 seconds.
If there is a modified buffer, retry it after 60 seconds."
(cond
;; Tramp is locked. Try it, again.
((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))
;; There's a modified buffer. Try it, again.
((seq-some
(lambda (buf)
(and-let* (((or (buffer-modified-p buf)
(with-current-buffer buf
;; We don't know whether autorevert.el has
;; been loaded alreaddy.
(tramp-compat-funcall 'auto-revert-active-p))))
(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
(concat
"Cannot timeout session (modified buffer), "
"trying it again in %s seconds.")
(tramp-get-method-parameter vec 'tramp-session-timeout))
(run-at-time
(tramp-get-method-parameter vec 'tramp-session-timeout) nil
#'tramp-timeout-session vec))
;; Do it.
(t (tramp-message
vec 3 "Timeout session %s" (tramp-make-tramp-file-name vec 'noloc))
(tramp-cleanup-connection vec 'keep-debug nil 'keep-processes)))
(tramp-cleanup-connection vec 'keep-debug nil 'keep-processes))))
(defun tramp-maybe-open-connection (vec)
"Maybe open a connection VEC.

View file

@ -8471,7 +8471,37 @@ process sentinels. They shall not disturb each other."
(cl-letf (((symbol-function #'ask-user-about-lock) #'always))
(save-buffer)))
(should-not
(string-match-p "File is missing:" captured-messages))))))
(string-match-p "File is missing:" captured-messages)))))
;; A modified buffer suppresses session timeout.
(with-temp-buffer
(set-visited-file-name tmp-name)
(insert "foo")
(should (buffer-modified-p))
(tramp-timeout-session tramp-test-vec)
(should
(process-live-p (tramp-get-connection-process tramp-test-vec)))
;; Steal the file lock.
(cl-letf (((symbol-function #'ask-user-about-lock) #'always))
(save-buffer))
(tramp-timeout-session tramp-test-vec)
(should-not
(process-live-p (tramp-get-connection-process tramp-test-vec))))
;; An auto-reverted buffer suppresses session timeout.
(with-temp-buffer
(set-visited-file-name tmp-name)
(auto-revert-mode 1)
;; Steal the file lock.
(cl-letf (((symbol-function #'ask-user-about-lock) #'always))
(save-buffer))
(tramp-timeout-session tramp-test-vec)
(should
(process-live-p (tramp-get-connection-process tramp-test-vec)))
(auto-revert-mode -1)
(tramp-timeout-session tramp-test-vec)
(should-not
(process-live-p (tramp-get-connection-process tramp-test-vec)))))
;; Cleanup.
(ignore-errors (delete-file tmp-name))))))