StackOverflow in compojure web project
- by Anders Rune Jensen
Hi
I've been playing around with clojure and have been using it to build a simple little audio player. The strange thing is that sometimes, maybe one out of twenty, when contact the server I will get the following error:
2010-04-20 15:33:20.963::WARN: Error for /control
java.lang.StackOverflowError
at clojure.lang.RT.seq(RT.java:440)
at clojure.core$seq__4245.invoke(core.clj:105)
at clojure.core$filter__5084$fn__5086.invoke(core.clj:1794)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:56)
at clojure.lang.RT.seq(RT.java:440)
at clojure.core$seq__4245.invoke(core.clj:105)
at clojure.core$filter__5084$fn__5086.invoke(core.clj:1794)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:56)
at clojure.lang.RT.seq(RT.java:440)
at clojure.core$seq__4245.invoke(core.clj:105)
at clojure.core$filter__5084$fn__5086.invoke(core.clj:1794)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:56)
at clojure.lang.RT.seq(RT.java:440)
at clojure.core$seq__4245.invoke(core.clj:105)
at clojure.core$filter__5084$fn__5086.invoke(core.clj:1794)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:56)
at clojure.lang.RT.seq(RT.java:440)
...
If I do it right after again it always works. So it appears to be related to timing or something. The code in question is:
(defn add-track [t]
(common/ref-add tracks t))
(defn add-collection [coll]
(doseq [track coll] (add-track track)))
and
(defn ref-add [ref value]
(dosync (ref-set ref (conj @ref value))))
where coll is extracted from this function:
(defn tracks-by-album [album]
(sort sort-tracks (filter #(= (:album %) album) @tracks)))
so it does appear to be the tracks-by-album function from the stack trace. I just don't see why it sometimes works and sometimes doesn't.