Hi! I'm trying to run some thing like lein run -m play.core/app and it just hangs. What's a good way to investigate this? lein run works in my other projects.
You can use something like jstack to get the stacks of all the threads in a jvm
There are some signals you can send to the jvm via kill that will cause it to print thread stacks as well
Or you can just comment out everything in play/core.clj and uncomment it form by form until you find the one that is causing the hang
Thanks! Turns out it actually ran everything, and then hang instead of exiting.
But... I still don't know why it doesn't exit.
It will exit after a minute
Why? what's that one minute for?
Clojure has some threadpools internally where the threads aren't marked as daemon threads, which for reasons causes the jvm not to exit for up to 60 seconds of those threadpools are ever used
You can call shutdown-agents to manually stop the threadpools
(the polls are the agent threadpools where agent actions get run, but there are a few other things like future and pmap which use one of the agent pools)
adding (shutdown-agents) didn't fix it.
Where did you add it?
It could be some other thread, not one from the clojure thread pools id preventing the jvm from exiting
The jvm won't exit until all non-daemon threads have stopped running, so just because the main thread stops that doesn't mean it will exit
I added it to the main function.
fwiw now my main function is just
(defn -main []
(prn "!!!")
(shutdown-agents))Now I run lein run play.core. still won't exit after printing the !!!.
Ah OK. it's some other code in the file that blocks it. After commenting out all other code but the main function, it exits properly.
Thanks!
> There are some signals you can send to the jvm via kill that will cause it to print thread stacks as well
For completeness, it's Ctrl+\ - can be handy in many situations :)