Skip to content

Commit

Permalink
CLJS-1759: Errors writing transit analysis cache if parallel build
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
mfikes authored and swannodette committed Aug 19, 2016
1 parent 86a83d7 commit 002708e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3110,6 +3110,9 @@
true
(util/changed? src cache)))))))

#?(:clj
(def transit-write-mutex (Object.)))

#?(:clj
(defn write-analysis-cache
([ns cache-file]
Expand All @@ -3124,10 +3127,11 @@
(str ";; Analyzed by ClojureScript " (util/clojurescript-version) "\n"))
(pr-str analysis)))
"json" (when-let [{:keys [writer write]} @transit]
(write
(writer (FileOutputStream. cache-file) :json
transit-write-opts)
analysis))))
(locking transit-write-mutex
(write
(writer (FileOutputStream. cache-file) :json
transit-write-opts)
analysis)))))
(when src
(.setLastModified ^File cache-file (util/last-modified src))))))

Expand Down

0 comments on commit 002708e

Please sign in to comment.