I work on a Java team, so our use of clojure is either

a) calling into clojure from java or
b) directly using the clojure data structures.

Recently we had an app fail because, as it was starting up, one thread was
trying to require a clojure namespace, and another was trying to use a
PersistentHashSet. Somehow these two threads wound up in deadlock. I've
reproduced the problem with minimal code here:

https://github.com/MichaelBlume/deadlock

Jstack output follows

"Thread-0" prio=5 tid=0x00007fa282077800 nid=0x5203 in Object.wait()
[0x000000015dce4000]
   java.lang.Thread.State: RUNNABLE
at clojure.lang.Util.hasheq(Util.java:170)
at clojure.lang.PersistentHashMap.hash(PersistentHashMap.java:120)
 at clojure.lang.PersistentHashMap.assoc(PersistentHashMap.java:142)
at clojure.lang.PersistentHashSet.cons(PersistentHashSet.java:99)
 at clojure.lang.PersistentHashSet.create(PersistentHashSet.java:27)
at clojure.core__init.__init3(Unknown Source)
 at clojure.core__init.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
 at clojure.lang.RT.loadClassForName(RT.java:2098)
at clojure.lang.RT.load(RT.java:430)
at clojure.lang.RT.load(RT.java:411)
 at clojure.lang.RT.doInit(RT.java:447)
at clojure.lang.RT.<clinit>(RT.java:329)
at deadlock.DeadLockMain$1.run(DeadLockMain.java:13)
 at java.lang.Thread.run(Thread.java:722)

"main" prio=5 tid=0x00007fa282001000 nid=0x1703 in Object.wait()
[0x0000000103429000]
   java.lang.Thread.State: RUNNABLE
at clojure.lang.Numbers$BigDecimalOps.<clinit>(Numbers.java:824)
at clojure.lang.Numbers.<clinit>(Numbers.java:937)
 at clojure.lang.Util.hasheq(Util.java:170)
at clojure.lang.PersistentHashMap.hash(PersistentHashMap.java:120)
 at clojure.lang.PersistentHashMap.assoc(PersistentHashMap.java:142)
at clojure.lang.PersistentHashSet.cons(PersistentHashSet.java:99)
 at deadlock.DeadLockMain.main(DeadLockMain.java:17)


I've reproduced this behavior with clojure 1.4.0, 1.5.1, and 1.6.0-alpha3
(though the attached project uses 1.5.1, it should be trivial to change its
dependency)

Is this expected behavior? Is the take-away don't use clojure data
structures from java code? Make sure the clojure runtime is warm before
using clojure data structures?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to