Subject: Re: bug#79182: 30.1; emacs becomes progressively less responsive up to become unusable

From: Michael Albinus <[email-masked]>
Date: Thu, 07 Aug 2025 13:33:42 +0200

Francesco Potortì <[email-masked]> writes:

Hi Francesco,

> By the way, would it make sense to put a limit on the number of lines
> in a debug Tramp buffer?

For a general fix with too large buffers there is the discussion with
Eli. Don't know, whether we will add such a check.

For the Tramp case, you might try the appended patch. It fires a warning
when the Tramp debug buffer exceeds a limit (tramp-debug-buffer-limit,
3GB by default).

Best regards, Michael.

diff --git a/lisp/tramp-message.el b/lisp/tramp-message.el
index 5131e5fc..7f66f7d8 100644
--- a/lisp/tramp-message.el
+++ b/lisp/tramp-message.el
@@ -94,6 +94,15 @@ This increases `tramp-verbose' to 6 if necessary."
   :type 'boolean
   :link '(info-link :tag "Tramp manual" "(tramp) Traces and Profiles"))
 
+(defcustom tramp-debug-buffer-limit (* 3 1024 1024 1024) ;3GB
+  "The upper limit of a Tramp debug buffer.
+If the size of a debug buffer exceeds this limit, a warning is raised.
+Set it to 0 if there is no limit."
+  :group 'tramp
+  :version "31.1"
+  :type 'natnum
+  :link '(info-link :tag "Tramp manual" "(tramp) Traces and Profiles"))
+
 (defconst tramp-debug-outline-regexp
   (rx ;; Timestamp.
       (+ digit) ":" (+ digit) ":" (+ digit) "." (+ digit) blank
@@ -281,7 +290,14 @@ ARGUMENTS to actually emit the message (if applicable)."
 	  (when tramp-debug-to-file
 	    (ignore-errors
 	      (write-region
-	       point (point-max) (tramp-get-debug-file-name vec) 'append))))))))
+	       point (point-max) (tramp-get-debug-file-name vec) 'append))))
+	(when (and (natnump tramp-debug-buffer-limit)
+		   (not (zerop tramp-debug-buffer-limit))
+		   (> (point-max) tramp-debug-buffer-limit))
+	  (setq-local tramp-debug-buffer-limit nil)
+	  (lwarn
+	   'tramp :warning
+	   "Tramp debug buffer %S exceeds the limit" (current-buffer)))))))
 
 ;;;###tramp-autoload
 (defun tramp-message (vec-or-proc level fmt-string &rest arguments)