Note that there are some explanatory texts on larger screens.

plurals
  1. POmongodb allanbank async driver callback being called twice
    primarykey
    data
    text
    <p>I have a simple callback bound to a <code>findAsync</code> call. Every few requests I observe a failure even though the data in the database is static. </p> <p>Some quick debugging shows that my callback is ALWAYS being called twice. The cases where my app fails are caused by a <code>null</code> <code>MongoIterator&lt;Document&gt;</code> being passed in to my callback. Of course I only expected a single callback when the data is ready (or if there was an exception).</p> <p>Is this expected behavior? Is there something I can do to ensure my callback is only called once when the query is complete?</p> <p>Here is the code snippet:</p> <pre><code>collection.findAsync( [ callback: { MongoIterator&lt;Document&gt; v -&gt; List data = [] try { while(v.hasNext()) { data.add(docToJson(v.next())) } } finally { if (v != null) v.close() } sendReply([ status: 'ok', data: data ]) }, exception: { Throwable t -&gt; sendReply([ status: 'error', message: t.message ]) } ] as Callback&lt;MongoIterator&lt;Document&gt;&gt;, find ) </code></pre> <p>Here is the stack trace:</p> <pre><code>Unexpected MongoDB Connection closed: Auth(MongoDB(43026--&gt;localhost/127.0.0.1:27017)). Will try to reconnect. Reconnected to localhost/127.0.0.1:27017 Exception in thread "MongoDB 43026&lt;--localhost/127.0.0.1:27017" java.lang.NullPointerException: Cannot invoke method hasNext() on null object at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112) at mongoAsync$_run_closure2_closure6.doCall(mongoAsync.groovy:126) at sun.reflect.GeneratedMethodAccessor54.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at groovy.lang.Closure.call(Closure.java:411) at org.codehaus.groovy.runtime.ConvertedMap.invokeCustom(ConvertedMap.java:50) at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:81) at com.sun.proxy.$Proxy14.callback(Unknown Source) at com.allanbank.mongodb.client.AbstractReplyCallback.handle(AbstractReplyCallback.java:82) at com.allanbank.mongodb.client.AbstractValidatingReplyCallback.callback(AbstractValidatingReplyCallback.java:72) at com.allanbank.mongodb.client.AbstractValidatingReplyCallback.callback(AbstractValidatingReplyCallback.java:33) at com.allanbank.mongodb.connection.message.ReplyHandler.reply(ReplyHandler.java:77) at com.allanbank.mongodb.connection.socket.SocketConnection.reply(SocketConnection.java:560) at com.allanbank.mongodb.connection.socket.SocketConnection$ReceiveRunnable.receiveOne(SocketConnection.java:735) at com.allanbank.mongodb.connection.socket.SocketConnection$ReceiveRunnable.run(SocketConnection.java:683) at java.lang.Thread.run(Thread.java:722) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload