Skip to content

Commit

Permalink
Add a polling fallback to filesystem watcher
Browse files Browse the repository at this point in the history
Changes to the latest beta version of macOS broke the mechanism that
we're using to observe filesystem change events. It's more than just
filesystem observation that has broken: any attempt to run a
hot-reloading workflow crashes the Figwheel process with an uncaught
exception at startup. (Note that build-once still works, since it
doesn't try to access filesystem events).

The underlying hawk library does have an implementation of a
less-efficient polling watcher. Figwheel can use this to provide
hot-reloading even when native events aren't available.

This commit wraps the `hawk.core/watch!` function to catch any exception
that's thrown, and re-try with the same options *except* that it
explicitly starts a polling watcher.

See also

- gjoseph/BarbaryWatchService#13
- java-native-access/jna#1216

Part of bhauman#253.
  • Loading branch information
rgm committed Jul 7, 2020
1 parent 947bba9 commit db0e84c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/figwheel/main/watching.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@

(def ^:dynamic *hawk-options* nil)

(defn watch-with-fallback!
"Wraps hawk/watch! to swap in a polling implementation if any of the native
OS file events interfaces fail."
[opts & groups]
(try
(apply hawk/watch! opts groups)
(catch Exception e
(prn e "WARN - no native fs events; falling back to polling filesystem")
(apply hawk/watch! (assoc opts :watcher :polling) groups))))

(defn alter-watches [{:keys [watcher watches]} f]
(when watcher (hawk/stop! watcher))
(let [watches (f watches)
watcher (when (not-empty watches)
(if *hawk-options*
(apply hawk/watch! *hawk-options* (map vector (vals watches)))
(apply hawk/watch! (map vector (vals watches)))))]
(apply watch-with-fallback! *hawk-options* (map vector (vals watches)))
(apply watch-with-fallback! (map vector (vals watches)))))]
{:watcher watcher
:watches watches}))

Expand Down

0 comments on commit db0e84c

Please sign in to comment.