Hi everyone ! I'm running into an issue with shadow-cljs on a work project and I don't really know what next steps to take to debug. On my computer, the watch process frequently hangs and the browser displays a red "shadow-cljs - Reconnecting…”, and the reload doesn't happen for a while (10-20 seconds). The problem is specific to this computer, on another machine it works fine with same project and very similar configuration. I created a minimal shadow-cljs project and tested hot reload there and everything worked flawlessly. I also tried launching the watch with --verbose, but when it stops responding, nothing extra is printed to the terminal. Is there any option / debug I could use to see exactly what's happening ? Thanks in advance!
does the work project use some significantly older shadow-cljs version maybe? thats my only guess really, unless you have :devtools-url configured in the build config and the entire thing goes through some kind of proxy?
but what does it mean that the "watch process frequently hangs"? the websocket connection logic is kinda independent from what the watch is doing, so not sure how they'd be related at all
I mean it could hang as in it compiles something for 20sec, that has been caused in the past by some bad behaving macros and such. running with --verbose should provide a clue to that
We are on 2.28.22 and no, no proxy just using the :dev-http and connecting from the same env to localhost:3000
By hang I mean doesn't detect the fact that a file was changed and doesn't recompile the project at all (which is why I'm assuming it is the watch but I could be wrong). And most likely also why --verbose doesn't help since it doesn't seem to even know yet that it should be doing something
does it run in a container of some sort?
The whole thing does run in WSL ( the linux virtual machine for windows) but I'm not using the windows layer, everything runs inside the VM including the browser so i'd be surprised if it mattered. Also on the other computer I tested with it also runs in WSL and is perfectly fine
vm and file watchers can be tricky. depends on what filesystem it is on I guess
if its any different than the minimal project you tried then thats the reason
I used windows for many years and typically ran everything directly in windows. less headaches that way
The minimal project was also in the WSL instance to replicate as much as possible the same conditions Yeah unfortunately my company only provided a windows computer and i'm not supposed to install a dual boot but the project doesn't run well on windows so I'm a bit stuck
don't see why it would work in one project but not another
The only difference I could see would be the project size, the work one is getting pretty large (few hundreds files) and uses modules Do you know of any large opensource clojurescript project I could try it on maybe ?
very much doubt that size has anything to do with it. I mean unless you see like 100% cpu usage or something being bottlenecked that way
Yeah I'd also be a little surprised but I don't really where else to look Cpu and disk usage is pretty low I'll try a few things, like bumping to latest and changing stuff around for a bit and keep you informed if I find anything And it at some point you have any idea of things I could try please don't hesitate to reach out ! Thanks for the help
in a REPL that has shadow-cljs on the classpath you can just try the watcher itself directly
(require '[shadow.cljs.devtools.server.fs-watch :as fsw])
(require '[ :as io])
(fsw/start {} [(io/file "src")] #{"cljs"} prn) that just prints any changes to .cljs files in the src directory
Same thing as --verbose, nothing is printed when "hanging"
However I was trying of few other things and when I call (runtime/get-instance!)I get an out of memory error, maybe that could be the cause
Error printing return value (OutOfMemoryError) at java.util.Arrays/copyOf (Arrays.java:3541).
; Requested array size exceeds VM limitif you call that at the REPL it'll try to print it. which is almost guaranteed to blow up since it contains circular references
doesn't mean anything and doesn't help identifying anything
Oh okay makes sense
Okay so I've moved forward a bit
The issue is not with the file watcher itself, it's working perfectly fine but with the shadow.cljs.devtools.server.fs-watch/watch-loopfunction
I noticed poll-changeswasn't getting called regularly like it should on my end and for some reason it seems the thread used by the watch loop is getting blocked somewhere in between calls (it's not exiting, just blocking for a while)
Though not great, as a proof of concept I removed the core.asyncstuff and replaced it with a basic Thread/sleep and it seems to be working fine now
Still need to figure out what's wrong with core.asyncon my setup though
hmm is there some server side stuff going on using core.async? maybe its threadpool is getting blocked? that is shared among all core.async and if used wrong can block everything
(assuming shadow-cljs is running embedded with you server side stuff of course)
wait no this is running as a thread, so no go involved
Could be yeah, I'm not super familiar with the async part it and I didn't think it was embedded in the server side Needs a bit more research on my side
maybe just an unexpected core.async version? best to use the one shadow-cljs expects
Seems like we are using the same 1.5.648 as shadow-cljs
( in the version of shadow-cljs that is used at least)
then no clue. I'm a bit skeptical that you are looking at the code in shadow-cljs. 99% of time its users code. shadow-cljs is used by quite a few people, something being wrong in the watch loop would come up more often if thats the cause 😛
Yeah no sorry, I didn't mean it as an issue with shadow-cljs itself, just plugging myself in it to get a bit more info on the issue since I don't have any other way of finding stuff out Since I'm the only one having this issue its most definitely on my side
I'd never rule out anything, but the loop is also rather basic
do you use wsl1 or wsl2? I had problems in the past with wsl2 using windows files directly. I only used wsl1 because of that basically
I'll keep you updated! It's wsl 2 but I'm really only using the linux filesystem, as far as I know nothing should be interacting with windows and it should be acting like a standalone vm But there could still be an weird issue that's true
you sure there are no symlinks involved? are the file changes actually triggered from windows (your editor) or on the linux side?
The editor is also running inside of the VM and just getting displayed in windows trough X11 forwarding (because of weird issues I got with calva when running in windows with the WSL extension, which are now fixed but i got used to this workflow so didn't switch back)
I also tried not using the editor at all and just touch file.cljsto test stuff and it was the same
do you use anything to relay this connection? like a nginx container in a docker compose file or such?
No i'm just running the clojure app through clojure -M:dev:run (the run alias lauches the watch) and connecting to a browser locally