[JAVA-155] StackOverflowError when fetching a tailable cursor after getting the last document Created: 25/Aug/10 Updated: 29/Oct/10 Resolved: 15/Sep/10 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 2.1 |
| Fix Version/s: | 2.2 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Sergey Shinderuk | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Sun Java 1.6_20 (64bit) db version v1.6.1, pdfile version 4.5 |
||
| Description |
|
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"); DBCursor cur = coll.find().sort(new BasicDBObject("$natural", 1)) 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 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. |
| Comments |
| Comment by auto [ 22/Sep/10 ] |
|
Author: {'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}Message: switch from recursion to while loop to avoid inf. recursion |
| Comment by Scott Hernandez (Inactive) [ 15/Sep/10 ] |
|
http://github.com/scotthernandez/mongo-java-driver/commit/66952e18ea560a4befbd07e0a48c852ec9040084 |