Jetty threads getting blocked and dead locked

1k views Asked by At

I am using jetty "7.6.8.v20121106" as a part of https://github.com/ring-clojure/ring/tree/master/ring-jetty-adapter with my server.

I am making calls using http://http-kit.org/ with following code. Essentially I am making server calls but ignoring the response. What I am finding is that all the server threads become blocked/deadlocked after that. This seems like a really easy way to bring to server down and wanted to understand what is going on here.

Code from client is:

(require '[org.httpkit.client :as hk-client])

 (defn hget [id]
   (hk-client/get (str "http://localhost:5000/v1/pubapis/auth/ping?ping=" id)))

(doall (map hget (take 100 (range))))) ; Gives problem
(doall (map deref (map hget (take 100 (range)))))) ; Doesn't give problem

Thread status Threads blocked at

sun.nio.cs.StreamEncoder.write(StreamEncoder.java:118)

and deadlocked at

java.io.PrintStream.write(PrintStream.java:479)

Would really appreciate if someone can help with what is going on over here.

1

There are 1 answers

2
Andy P On BEST ANSWER

Finally found what the problem was. Took lot of digging through and starting with a sample project to find this. When I started learning clojure and copied the following from somewhere for logging:

(defn log [msg & vals]
  (let [line (apply format msg vals)]
    (locking System/out (println line))))

The line locking over there was causing dead lock in some situation. Do not know enough about concurrency to solve this. Will create a separate question for that.

Removing this line fixes the problem.