Skip to content

Commit 002708e

Browse files
mfikesswannodette
authored andcommitted
CLJS-1759: Errors writing transit analysis cache if parallel build
Adds a coarse-grained mutex around the calls to write out transit analysis cache data. A result of this is that sporadic failures that only occur when concurrently writing out analysis cache info when compiling largeish multi-file projects with :parallel-build true is avoided. (Perhaps there is some thread-safety defect in the transit-clj stack yet to be discovered / fixed, and this patch acts as a suitable workaround until a proper solution is found.)
1 parent 86a83d7 commit 002708e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/main/clojure/cljs/analyzer.cljc

+8-4
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,9 @@
31103110
true
31113111
(util/changed? src cache)))))))
31123112

3113+
#?(:clj
3114+
(def transit-write-mutex (Object.)))
3115+
31133116
#?(:clj
31143117
(defn write-analysis-cache
31153118
([ns cache-file]
@@ -3124,10 +3127,11 @@
31243127
(str ";; Analyzed by ClojureScript " (util/clojurescript-version) "\n"))
31253128
(pr-str analysis)))
31263129
"json" (when-let [{:keys [writer write]} @transit]
3127-
(write
3128-
(writer (FileOutputStream. cache-file) :json
3129-
transit-write-opts)
3130-
analysis))))
3130+
(locking transit-write-mutex
3131+
(write
3132+
(writer (FileOutputStream. cache-file) :json
3133+
transit-write-opts)
3134+
analysis)))))
31313135
(when src
31323136
(.setLastModified ^File cache-file (util/last-modified src))))))
31333137

0 commit comments

Comments
 (0)