Subject: bug#48379: 27.2; ispell-init-process may be called recursively during sit-for

From: [email-masked]
Date: Wed, 12 May 2021 16:14:07 +0200

In ispell-init-process, sit-for can accept process output, which may in
turn call ispell-init-process again, recursively. If needed, I can post
a short reproducer.

This recursive call results in the following sequence of events:

    (ispell-kill-ispell t)
    (ispell-kill-ispell t)
    (setq ispell-process (ispell-start-process))
    (setq ispell-process (ispell-start-process))

where the middle two calls happen recursively from within sit-for. As
you can see, this creates one extra useless ispell process.

The following simple patch fixes this by moving the killing of the
process closer to starting of the new process without sit-for in the
middle

diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index 4dbc7640bc..80ddb4861f 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -2865,8 +2865,6 @@ ispell-init-process
 	     (or (or ispell-local-pdict ispell-personal-dictionary)
 		 (equal ispell-process-directory default-directory)))
 	(setq ispell-filter nil ispell-filter-continue nil)
-      ;; may need to restart to select new personal dictionary.
-      (ispell-kill-ispell t)
       (let ((reporter
              (make-progress-reporter
               (format "Starting new Ispell process %s with %s dictionary..."
@@ -2874,6 +2872,8 @@ ispell-init-process
 	              (or ispell-local-dictionary ispell-dictionary
                           "default")))))
         (sit-for 0)
+        ;; May need to restart to select new personal dictionary.
+        (ispell-kill-ispell t)
         (setq ispell-library-directory (ispell-check-version)
               ;; Assign a non-nil value to ispell-process-directory
               ;; before calling ispell-start-process, since that

Best regards.