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.
This commit is contained in:
Eric Abrahamsen 2021-10-11 08:45:09 -07:00
parent 85edcf7af5
commit e47b85a683

View 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