figwheel-main
figwheel-main copied to clipboard
Figwheel node process easily hangs and must be restarted
I'm using figheel.main with node, and the process locks and needs to be restarted quite frequently.
To reproduce, start a figwheel-main REPL, using this config:
^{:watch-dirs ["src"]
:open-file-command "emacsclient"}
{:main "myapp.dev"
:optimizations :none
:pretty-print true
:target :nodejs
:source-map true
:npm-deps {:puppeteer "1.8.0"
:minimist "1.2.0"}
:install-deps true}
Then do this:
(def http (js/require "http"))
(http.request
{:host "somewhere.com"
:path "/api/hello"
:method "POST"
:headers {"Content-Type" "application/json"}}
(fn [res]
(println res)))
Now, as you can see I forgot to wrap my parameters in (clj->js)
, and so I'm passing an opaque object to http.request
, which causes it to fail, and then the process freezes. The log says:
[Figwheel REPL] Session ID: 50e09152-e516-40f8-b835-af2593675710
[Figwheel REPL] Session Name: Elmo
nhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:80
at Object._errnoException (util.js:1024:11)
at _exceptionWithHostPort (util.js:1046:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
At this point, the REPL refuses to evaluate anything, even simple (js/console.log "Hello")
just hangs. If I save files, then figwheel sees that and starts compiling, but never finishes. Save another file, and it'll print "[Figwheel] Compiling build dev to "target/node/dev/dev-main.js"
again, but it never completes and the REPL is effectively dead.
Verified on both 0.1.9 and 0.2.0-SNAPSHOT.
I was about to mention that this is not the only way to trigger this problem - any node error will do. And then it hit me - Figwheel does not set up uncaughtException
or unhandledRejection
handlers, so any runtime error will kill the REPL. I suggest that Figwheel adds those handlers to provide a better developent experience.
I have noticed this too and it is definitely confusing (especially in cider)