emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master e47b85a: Clean up nnimap buffers with dead processes


From: Eric Abrahamsen
Subject: master e47b85a: Clean up nnimap buffers with dead processes
Date: Tue, 12 Oct 2021 16:48:21 -0400 (EDT)

branch: master
commit e47b85a68339063dd3a784e8b90aecbf90b23f41
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>

    Clean up nnimap buffers with dead processes
    
    * lisp/gnus/nnimap.el (nnimap-keepalive): If the keepalive "NOOP"
    fails, remove the buffer with the dead process from
    `nnimap-process-buffers' and `nnimap-connection-alist'.
    (nnimap-find-connection): Do the same here, when the connection can't
    be found.
    (nnimap-close-server): Remove process buffer from lists when closing
    server.
---
 lisp/gnus/nnimap.el | 38 +++++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 059101c..8a2acf6 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -429,8 +429,18 @@ during splitting, which may be slow."
                       now
                       (nnimap-last-command-time nnimap-object))))
             (with-local-quit
-              (ignore-errors          ;E.g. "buffer foo has no process".
-                (nnimap-send-command "NOOP")))))))))
+              (ignore-errors        ;E.g. "buffer foo has no process".
+                (nnimap-send-command "NOOP"))
+              ;; If our connection has died in the meantime, clean it
+              ;; and its buffer up.
+              (unless (process-live-p (get-buffer-process buffer))
+               (setq nnimap-process-buffers
+                     (delq buffer nnimap-process-buffers))
+               (setq nnimap-connection-alist
+                     (seq-filter (lambda (elt)
+                                   (null (eq buffer (cdr elt))))
+                                 nnimap-connection-alist))
+               (kill-buffer buffer)))))))))
 
 (defun nnimap-open-connection (buffer)
   ;; Be backwards-compatible -- the earlier value of nnimap-stream was
@@ -662,10 +672,17 @@ during splitting, which may be slow."
 
 (deffoo nnimap-close-server (&optional server defs)
   (when (nnoo-change-server 'nnimap server defs)
-    (ignore-errors
-      (delete-process (get-buffer-process (nnimap-buffer))))
-    (nnoo-close-server 'nnimap server)
-    t))
+    (let ((buf (nnimap-buffer)))
+      (ignore-errors
+        (delete-process (get-buffer-process buf)))
+      (setq nnimap-process-buffers
+            (delq buf nnimap-process-buffers)
+            nnimap-connection-alist
+           (seq-filter (lambda (elt)
+                         (null (eq buf (cdr elt))))
+                       nnimap-connection-alist))
+      (nnoo-close-server 'nnimap server)
+      t)))
 
 (deffoo nnimap-request-close ()
   t)
@@ -1937,10 +1954,13 @@ Return the server's response to the SELECT or EXAMINE 
command."
     (when entry
       (if (and (buffer-live-p (cadr entry))
               (get-buffer-process (cadr entry))
-              (memq (process-status (get-buffer-process (cadr entry)))
-                    '(open run)))
+              (process-live-p (get-buffer-process (cadr entry))))
          (get-buffer-process (cadr entry))
-       (setq nnimap-connection-alist (delq entry nnimap-connection-alist))
+       (setq nnimap-connection-alist (delq entry nnimap-connection-alist)
+              nnimap-process-buffers
+             (delq (cadr entry) nnimap-process-buffers))
+       (when (buffer-live-p (cadr entry))
+         (kill-buffer (cadr entry)))
        nil))))
 
 ;; Leave room for `open-network-stream' to issue a couple of IMAP



reply via email to

[Prev in Thread] Current Thread [Next in Thread]