Skip to content

Commit

Permalink
middleware.refresh: elide a lock for the "refresh-clear" op
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed May 5, 2024
1 parent b7aace8 commit c2a4fcb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Add `inspect-set-max-nested-depth` op that customizes how many nested levels the Inspector will print before abridging.
* [#826](https://github.com/clojure-emacs/cider-nrepl/pull/826): Remove broken `inspect-get-path` middleware op, return path in every inspector middleware op instead.
* Reduce the print length of values that CIDER debugger produces for overlay.
* [cider#3652](https://github.com/clojure-emacs/cider/issues/3652) `middleware.refresh`: elide a lock for the `"refresh-clear"` op.

## 0.47.1 (2024-03-24)

Expand Down
17 changes: 14 additions & 3 deletions src/cider/nrepl/middleware/refresh.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,18 @@
msg]
(reload-utils/after-reply error msg))

(def ^{:added "0.48.0"} user-indicated-clear?
"Whether the user indicated that a `clear` is desired."
(atom false))

(defn- refresh-reply
[{:keys [dirs transport session id] :as msg}]
(let [{:keys [exec]} (meta session)]
(exec id
(fn []
(locking refresh-tracker
(when @user-indicated-clear?
(vreset! refresh-tracker (track/tracker)))
(vswap! refresh-tracker
(fn [tracker]
(try
Expand All @@ -98,7 +104,10 @@

(catch Throwable e
(reload-utils/error-reply {:error e} msg)
tracker))))))
tracker)

(finally
(reset! user-indicated-clear? false)))))))
(fn []
(transport/send transport (response-for msg {:status :done}))))))

Expand All @@ -107,8 +116,10 @@
(let [{:keys [exec]} (meta session)]
(exec id
(fn []
(locking refresh-tracker
(vreset! refresh-tracker (track/tracker))))
;; This used to be a `locking`-based call to our `clear` implementation
;; Now it merely "enqueues" a clearing, because the "refresh-clear" op is called synchronously by CIDER,
;; so the `locking` could cause timeouts (https://github.com/clojure-emacs/cider/issues/3652 )
(reset! user-indicated-clear? true))
(fn []
(transport/send transport (response-for msg {:status :done}))))))

Expand Down

0 comments on commit c2a4fcb

Please sign in to comment.