]> git.eshelyaron.com Git - emacs.git/commitdiff
Clean up nnimap buffers with dead processes
authorEric Abrahamsen <eric@ericabrahamsen.net>
Mon, 11 Oct 2021 15:45:09 +0000 (08:45 -0700)
committerEric Abrahamsen <eric@ericabrahamsen.net>
Tue, 12 Oct 2021 20:00:05 +0000 (13:00 -0700)
* 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

index 059101c8907ecab82bbaea7a402484755e1e82dd..8a2acf6459a5882b01bca3cdba9fe0d8c36539ce 100644 (file)
@@ -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