shadow-cljs

Nathan G 2025-07-03T18:54:01.989539Z

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!

thheller 2025-07-04T07:13:30.076729Z

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?

thheller 2025-07-04T07:14:04.226989Z

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

thheller 2025-07-04T07:15:11.955359Z

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

Nathan G 2025-07-04T21:57:21.371399Z

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

thheller 2025-07-05T05:58:12.670439Z

does it run in a container of some sort?

Nathan G 2025-07-05T09:15:13.298179Z

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

thheller 2025-07-05T09:16:06.272189Z

vm and file watchers can be tricky. depends on what filesystem it is on I guess

thheller 2025-07-05T09:16:26.349439Z

if its any different than the minimal project you tried then thats the reason

thheller 2025-07-05T09:16:54.651379Z

I used windows for many years and typically ran everything directly in windows. less headaches that way

Nathan G 2025-07-05T09:18:47.741949Z

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

thheller 2025-07-05T09:19:41.302349Z

don't see why it would work in one project but not another

Nathan G 2025-07-05T09:22:37.026859Z

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 ?

thheller 2025-07-05T09:25:42.022309Z

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

Nathan G 2025-07-05T09:30:05.537799Z

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

thheller 2025-07-05T09:31:12.464949Z

in a REPL that has shadow-cljs on the classpath you can just try the watcher itself directly

thheller 2025-07-05T09:32:53.752829Z

(require '[shadow.cljs.devtools.server.fs-watch :as fsw])
  (require '[ :as io])

  (fsw/start {} [(io/file "src")] #{"cljs"} prn)

thheller 2025-07-05T09:33:13.539539Z

that just prints any changes to .cljs files in the src directory

Nathan G 2025-07-05T09:52:13.963859Z

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 limit

thheller 2025-07-05T09:54:38.276779Z

if you call that at the REPL it'll try to print it. which is almost guaranteed to blow up since it contains circular references

thheller 2025-07-05T09:55:02.555329Z

doesn't mean anything and doesn't help identifying anything

Nathan G 2025-07-05T09:55:12.975279Z

Oh okay makes sense

Nathan G 2025-07-05T15:42:21.318379Z

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

thheller 2025-07-05T15:43:26.537189Z

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

thheller 2025-07-05T15:44:40.707619Z

(assuming shadow-cljs is running embedded with you server side stuff of course)

thheller 2025-07-05T15:48:40.756369Z

wait no this is running as a thread, so no go involved

Nathan G 2025-07-05T15:48:47.682619Z

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

thheller 2025-07-05T15:49:16.986349Z

maybe just an unexpected core.async version? best to use the one shadow-cljs expects

Nathan G 2025-07-05T15:51:27.596919Z

Seems like we are using the same 1.5.648 as shadow-cljs

Nathan G 2025-07-05T15:52:18.206969Z

( in the version of shadow-cljs that is used at least)

thheller 2025-07-05T15:53:45.999159Z

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 😛

Nathan G 2025-07-05T15:55:12.389359Z

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

thheller 2025-07-05T15:55:23.583669Z

I'd never rule out anything, but the loop is also rather basic

thheller 2025-07-05T15:56:17.209259Z

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

Nathan G 2025-07-05T15:58:16.373999Z

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

thheller 2025-07-05T16:01:52.299489Z

you sure there are no symlinks involved? are the file changes actually triggered from windows (your editor) or on the linux side?

Nathan G 2025-07-05T16:06:21.749289Z

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

valerauko 2025-07-03T19:09:59.360429Z

do you use anything to relay this connection? like a nginx container in a docker compose file or such?

Nathan G 2025-07-03T19:19:08.819149Z

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