mongo-java: StackOverflowError when fetching a tailable cursor

292 views
Skip to first unread message

Sergey Shinderuk

unread,
Aug 25, 2010, 10:32:43 AM8/25/10
to mongodb-user
I am trying to use Mongo tailable cursor to fetch docs from a capped
collection.
I use mongo-java driver ver. 2.1. and constantly receive a
StackOverflowError.

Below are the code snippet reproducing the error, the stack trace, and
capped collection stats from mongo shell.

Am I doing something wrong?

db version v1.6.1, pdfile version 4.5
git hash: c5f5f9a4f3b515dfd5272d373093fd4fd58c95d9
sys info: Linux xxxx 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28
06:21:40 UTC 2010 x86_64 BOOST_LIB_VERSION=1_40

----------------------------------------------

package test;

import com.mongodb.*;

public class Test {

public static void main(String[] args) throws Exception {

Mongo mongo = new Mongo("localhost");
DB db = mongo.getDB("test");
DBCollection coll = db.getCollection("mycoll");

DBCursor cur = coll.find().sort(new BasicDBObject("$natural", 1))
.addOption(Bytes.QUERYOPTION_TAILABLE);

while (cur.hasNext()) {
System.out.println(cur.next());
}
}
}


And here is the stacktrace:

Exception in thread "main" java.lang.StackOverflowError
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at org.bson.io.Bits.readFully(Bits.java:30)
at com.mongodb.Response.<init>(Response.java:34)
at com.mongodb.DBPort.go(DBPort.java:85)
at com.mongodb.DBPort.call(DBPort.java:56)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:186)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:173)
at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:328)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:311)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:312)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:312)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:312)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:312)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:312)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:312)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:312)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:312)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:312)
<...>

Collection 'mycoll' stats

{
"ns" : "test.mycoll",
"count" : 200,
"size" : 7200,
"avgObjSize" : 36,
"storageSize" : 1000192,
"numExtents" : 1,
"nindexes" : 0,
"lastExtentSize" : 1000192,
"paddingFactor" : 1,
"flags" : 0,
"totalIndexSize" : 0,
"indexSizes" : {

},
"capped" : 1,
"max" : 2147483647,
"ok" : 1
}

Sergey Shinderuk

unread,
Aug 25, 2010, 12:12:33 PM8/25/10
to mongodb-user
It seems to work better, if i add QUERYOPTION_AWAITDATA option

DBCursor cur = coll.find().sort(new BasicDBObject("$natural", 1))
.addOption(Bytes.QUERYOPTION_TAILABLE)
.addOption(Bytes.QUERYOPTION_AWAITDATA);


But stack will nevertheless overflow, if documents are not added to
the collection for a long period of time.

Eliot Horowitz

unread,
Aug 25, 2010, 12:16:56 PM8/25/10
to mongod...@googlegroups.com
Can you open a jira case?
http://jira.mongodb.org/

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Sergey Shinderuk

unread,
Aug 25, 2010, 3:00:28 PM8/25/10
to mongodb-user
Sure :)
http://jira.mongodb.org/browse/JAVA-155

On Aug 25, 8:16 pm, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> Can you open a jira case?http://jira.mongodb.org/

chinthaka dharmasiri

unread,
Apr 15, 2014, 12:31:56 PM4/15/14
to mongod...@googlegroups.com

I also have the same issue. hasNext() seems to never return until the connection timeouts and re-establishes.

Any solution on how we can query the results in Java?

Asya Kamsky

unread,
Apr 20, 2014, 3:03:31 PM4/20/14
to mongodb-user
Please don't revive four year old threads to say "I have the same problem" - it is really unlikely you are using the same version of anything that someone would have been using four years ago.

Please start a new thread describing your problem as completely as you can.

Asya



For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages