]> git.eshelyaron.com Git - emacs.git/commitdiff
Cancel timeouts when process dies unexpectedly
authorJoão Távora <joaotavora@gmail.com>
Wed, 16 Aug 2017 11:58:20 +0000 (12:58 +0100)
committerJoão Távora <joaotavora@gmail.com>
Wed, 16 Aug 2017 12:52:00 +0000 (13:52 +0100)
lisp/progmodes/eglot.el

index e3b288b0381c0098c3597dead5a7d3f77d144ebf..5699775a2bbebc1c89af89322bf0068863fc0688 100644 (file)
   (with-current-buffer (process-buffer process)
     (eglot--debug "Process state changed to %s" change)
     (when (not (process-live-p process))
+      ;; Remember to cancel all timers
+      ;;
+      (maphash (lambda (id v) 
+                 (cl-destructuring-bind (_success _error timeout) v
+                   (eglot--message "Cancelling timer for continuation %s" id)
+                   (cancel-timer timeout)))
+               (eglot--pending-continuations process))
       (cond ((process-get process 'eglot--moribund)
              (eglot--message "Process exited with status %s"
-                              (process-exit-status process)))
+                             (process-exit-status process)))
             (t
              (eglot--warn "Process unexpectedly changed to %s" change))))))
 
                                       :method  ,method
                                       :params  ,params))
     (catch catch-tag
-      (puthash id
-               (list (if async-p
-                         success-fn
-                       (lambda (&rest args)
-                         (throw catch-tag (apply success-fn args))))
-                     (if async-p
-                         error-fn
-                       (lambda (&rest args)
-                         (throw catch-tag (apply error-fn args))))
-                     (run-with-timer 5 nil
-                                     (if async-p
-                                         timeout-fn
-                                       (lambda ()
-                                         (throw catch-tag (apply timeout-fn))))))
-               (eglot--pending-continuations process))
-      (unless async-p
-        (while t
-          (unless (eq (process-status process) 'open)
-            (eglot--error "Process %s died unexpectedly" process))
-          (accept-process-output nil 0.01))))))
+      (let ((timeout-timer
+             (run-with-timer 5 nil
+                             (if async-p
+                                 timeout-fn
+                               (lambda ()
+                                 (throw catch-tag (apply timeout-fn)))))))
+        (puthash id
+                 (list (if async-p
+                           success-fn
+                         (lambda (&rest args)
+                           (throw catch-tag (apply success-fn args))))
+                       (if async-p
+                           error-fn
+                         (lambda (&rest args)
+                           (throw catch-tag (apply error-fn args))))
+                       timeout-timer)
+                 (eglot--pending-continuations process))
+        (unless async-p
+          (unwind-protect
+              (while t
+                (unless (process-live-p process)
+                  (eglot--error "Process %s died unexpectedly" process))
+                (accept-process-output nil 0.01))
+            (cancel-timer timeout-timer)))))))
 
 \f
 ;;; Requests