emacs-diffs
[Top][All Lists]
Advanced

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

master 146bd41ddef: Fix another race condition when waiting for Eshell p


From: Jim Porter
Subject: master 146bd41ddef: Fix another race condition when waiting for Eshell processes
Date: Mon, 18 Sep 2023 13:26:52 -0400 (EDT)

branch: master
commit 146bd41ddef21a19634e2b90db4bfb619a2091b2
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>

    Fix another race condition when waiting for Eshell processes
    
    When checking if the other processes in our pipeline are "alive", we
    also need to check whether their sentinels are finished.  Otherwise,
    we might proceed with command evaluation while one of the other
    processes is still cleaning up.
    
    * lisp/eshell/esh-proc.el (eshell-process-active-p): New function...
    (eshell-wait-for-process)
    * lisp/eshell/esh-cmd.el (eshell-resume-command): ... use it.
---
 lisp/eshell/esh-cmd.el  |  2 +-
 lisp/eshell/esh-proc.el | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 0d73b2d6e69..af50a485226 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -1018,7 +1018,7 @@ process(es) in a cons cell like:
              ;; Make sure PROC is one of our foreground processes and
              ;; that all of those processes are now dead.
              (member proc eshell-last-async-procs)
-             (not (seq-some #'process-live-p eshell-last-async-procs)))
+             (not (seq-some #'eshell-process-active-p 
eshell-last-async-procs)))
     (eshell-resume-eval)))
 
 (defun eshell-resume-eval ()
diff --git a/lisp/eshell/esh-proc.el b/lisp/eshell/esh-proc.el
index aed8f8af93d..e564c755320 100644
--- a/lisp/eshell/esh-proc.el
+++ b/lisp/eshell/esh-proc.el
@@ -157,15 +157,21 @@ The signals which will cause this to happen are matched by
     (declare-function eshell-reset "esh-mode" (&optional no-hooks))
     (eshell-reset)))
 
+(defun eshell-process-active-p (process)
+  "Return non-nil if PROCESS is active.
+This is like `process-live-p', but additionally checks whether
+`eshell-sentinel' has finished all of its work yet."
+  (or (process-live-p process)
+      ;; If we have handles, this is an Eshell-managed
+      ;; process.  Wait until we're 100% done and have
+      ;; cleared out the handles (see `eshell-sentinel').
+      (process-get process :eshell-handles)))
+
 (defun eshell-wait-for-process (&rest procs)
   "Wait until PROCS have successfully completed."
   (dolist (proc procs)
     (when (eshell-processp proc)
-      (while (or (process-live-p proc)
-                 ;; If we have handles, this is an Eshell-managed
-                 ;; process.  Wait until we're 100% done and have
-                 ;; cleared out the handles (see `eshell-sentinel').
-                 (process-get proc :eshell-handles))
+      (while (eshell-process-active-p proc)
         (when (input-pending-p)
           (discard-input))
         (sit-for eshell-process-wait-seconds



reply via email to

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