oliyh / re-graph

A graphql client for clojurescript and clojure
460 stars 39 forks source link

hangs in clojure #75

Closed mobileink closed 2 years ago

mobileink commented 3 years ago

Hi, I'm trying to get re-graph working in a clojure command-line app. Following the examples, nothing happens, and the program will not exit, even if I add (shutdown-agents) at the end. E.g.

(defn -main
  [& args]

  (println "entering main")
  (re-graph/init {:ws-url   "ws://localhost:3086/graphql-ws"
                  :http-url "http://localhost:3085/graphql"})
  (println "exiting main")
  (shutdown-agents))

Running it:

$ clojure -M -m mina.repl
entering main
exiting main
...hangs...

Adding the example code to send a query has no effect. What am I doing wrong?

oliyh commented 3 years ago

Hi,

You should call re-graph/destroy when you have finished with it. I wouldn't expect it to hang forever without this though. Which http client are you using, hato (default) or gniazdo? (See readme for details).

Cheers

mobileink commented 3 years ago

There's nothing in the readme about re-graph/destroy, and I don't see any other documentation. I'm using hato.

oliyh commented 3 years ago

Yes I realised when I replied that destroy is undocumented, I have added that.

I will try to replicate your issue, in the meantime are you able to take a thread dump while it is hanging? That would help greatly.

Thanks Oliy

oliyh commented 2 years ago

Closing this as no update, please let me know if you still face issues.

Cheers

oliyh commented 2 years ago

Was able to reproduce and found this non-daemon thread preventing shutdown:

"pool-2-thread-1" #16 prio=5 os_prio=0 cpu=235.02ms elapsed=41.72s tid=0x00007f11524f3000 nid=0x67fb4 waiting on condition  [0x00007f11251fc000]
   java.lang.Thread.State: WAITING (parking)
    at jdk.internal.misc.Unsafe.park(java.base@11.0.15/Native Method)
    - parking to wait for  <0x000000070c400170> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(java.base@11.0.15/LockSupport.java:194)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(java.base@11.0.15/AbstractQueuedSynchronizer.java:2081)
    at java.util.concurrent.LinkedBlockingQueue.take(java.base@11.0.15/LinkedBlockingQueue.java:433)
    at java.util.concurrent.ThreadPoolExecutor.getTask(java.base@11.0.15/ThreadPoolExecutor.java:1054)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@11.0.15/ThreadPoolExecutor.java:1114)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@11.0.15/ThreadPoolExecutor.java:628)
    at java.lang.Thread.run(java.base@11.0.15/Thread.java:829)

Turns out it was the executor from here: https://github.com/day8/re-frame/blob/master/src/re_frame/interop.clj#L26

Going to talk to re-frame devs to find out more. Short term workaround is to kill that executor.