-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.1
-
Component/s: None
-
None
-
Environment:Sun Java 1.6_20 (64bit)
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
When iterating through a capped collection via a tailable cursor, I get a StackOverflowError as soon as the cursor reaches the end of the collection.
Error can be reproduced by running the code below:
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()); } }
}
After reading the last document, cursor.hasNext() will result in a StackOverflowError. Here is the stack trace:
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)
<...>
The problem is shadowed if a cursor is created with QUERYOPTION_AWAITDATA option. The stack will nevertheless fill up because of recursion, but much slower.