I use mongodb in a multithreaded clojure application using the monger library and one of my producer threads dies with
java.lang.IllegalStateException: state should be: open at com.mongodb.assertions.Assertions.isTrue (Assertions.java:70) com.mongodb.connection.DefaultServer.getConnection (DefaultServer.java:84) com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection (ClusterBinding.java:86) com.mongodb.operation.QueryBatchCursor.getMore (QueryBatchCursor.java:205) com.mongodb.operation.QueryBatchCursor.hasNext (QueryBatchCursor.java:103) com.mongodb.MongoBatchCursorAdapter.hasNext (MongoBatchCursorAdapter.java:46) com.mongodb.DBCursor.hasNext (DBCursor.java:155) clojure.lang.RT$4.invoke (RT.java:512) clojure.lang.LazySeq.sval (LazySeq.java:40) clojure.lang.LazySeq.seq (LazySeq.java:49) clojure.lang.RT.seq (RT.java:525) clojure.core$seq__6416.invokeStatic (core.clj:137) clojure.core$map$fn__6875.invoke (core.clj:2719) clojure.lang.LazySeq.sval (LazySeq.java:40) clojure.lang.LazySeq.seq (LazySeq.java:49) clojure.lang.RT.seq (RT.java:525) clojure.core$seq__6416.invokeStatic (core.clj:137) clojure.core$map$fn__6875.invoke (core.clj:2719) clojure.lang.LazySeq.sval (LazySeq.java:40) clojure.lang.LazySeq.seq (LazySeq.java:49) clojure.lang.RT.seq (RT.java:525) clojure.core$seq__6416.invokeStatic (core.clj:137) clojure.core$filter$fn__6902.invoke (core.clj:2782) clojure.lang.LazySeq.sval (LazySeq.java:40) clojure.lang.LazySeq.seq (LazySeq.java:49) clojure.lang.ChunkedCons.chunkedNext (ChunkedCons.java:59) clojure.lang.ChunkedCons.next (ChunkedCons.java:43) clojure.lang.RT.next (RT.java:703) clojure.core$next__6400.invokeStatic (core.clj:64) clojure.core$dorun.invokeStatic (core.clj:3115) clojure.core$doall.invokeStatic (core.clj:3121) clojure.core$doall.invoke (core.clj:3121) myapp.ns1.$somefn.invokeStatic (ns1.clj:93) myapp.ns1.$somefn.invoke (ns1.clj:90) myapp.ns1$anotherfn.invokeStatic (ns1.clj:124) myapp.ns1$anotherfn.invoke (ns1.clj:116) myapp.ns2$doit.invokeStatic (ns2:21) myapp.ns2$doit.invoke (ns2:17) myapp.ns2$producer$fn__11200.invoke (ns2:45) myapp.ns2$producer.invokeStatic (ns2:31) myapp.ns2$producer.invoke (ns2:25) myapp.ns2$_start$fn__11230.invoke (ns2:70) clojure.core$binding_conveyor_fn$fn__6766.invoke (core.clj:2020) clojure.lang.AFn.call (AFn.java:18) java.util.concurrent.FutureTask.run (FutureTask.java:266) java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617) java.lang.Thread.run (Thread.java:745)
I found several other hits for this problem, and all of them were resolved by removing some call to conn.close() .
I have one connection that I create at startup, and the only place I call close is at shutdown time. The java driver controls threadpool, so I'm not quite sure what kind of connection we are talking about. Does a DbObject return from a query its own dedicated connection, and this connection dies?
I tried to fix this by specifying :socket-keep-alive true and explicitly setting :socket-timeout to 0 (which is the default and means unlimited), but to no avail.
While some use of with-open , which, as I understand it, can cause a problem that I am facing. Secondly, I accidentally tried to remove all reuse of db objects, but this did not affect the work.
Another thought was that with-open might interact poorly with lazy stuff inside, but wrapping everything in a doall to make it impatient also had no effect.
I work against a set of replicas, and I run locally on a subordinate mongodb with ReadPreference/secondary .
Any other ideas as to what might be wrong?
multithreading mongodb clojure mongodb-java monger
expez
source share