[JAVA-572] Empty tailable cursor can't be explicitly closed with DBCursor.close() Created: 23/May/12 Updated: 01/May/14 Resolved: 01/May/14 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API, Cluster Management |
| Affects Version/s: | 2.7.3 |
| Fix Version/s: | 2.12.0 |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Jared D. Cottrell | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 2 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Java 2.6, Mongo Java Driver 2.7.3, Mac OS X 10.7, MongoDB 2.0.4 64-bit |
||
| Description |
|
We're trying to tail the oplog for any changes to a very slow-moving collection. We have observed that to properly establish a tailable cursor it does initially have to return at least one result. However, with these collections that process can take a long time. Possibly days in some cases. In the meantime, we have to retry our query in a loop, creating a new cursor each time. But those empty cursors don't close explicitly by calling close(). We have to wait for them to time out. The core section of our code is below, largely inspired by the example in the Mongo Java driver itself (https://github.com/mongodb/mongo-java-driver/blob/master/examples/ReadOplog.java) and the Worknik open source tools (https://github.com/wordnik/wordnik-oss/blob/master/modules/mongo-admin-utils/src/main/java/com/wordnik/system/mongodb/OplogTailThread.java).
Looking into DBCursor.close() it looks like it's testing the type of the internal rep and returning fast if it's not a Result. If I look at db.runCommand( {cursorInfo:1}) while our code is executing I see total cursors growing with each time through the first loop. Of course they eventually timeout, but we can build up a lot of cursors in the 10 minutes that takes. I'm guessing, though haven't verified, that when that initial query returns no results _it isn't a Result and so close() does nothing. But elsewhere the logic to close exhausted cursors is noticing that this cursor is tailable and so not closing it even though hasNext() returns false.
|
| Comments |
| Comment by Jeffrey Yemin [ 01/May/14 ] | |||||||||||||||||||||||||||||
|
Based on the test program in the last comment, this was fixed in 2.12.0. | |||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 31/Jan/14 ] | |||||||||||||||||||||||||||||
|
This issue is rather old, but as we've made some changes around tailable cursor handling for 2.12.0, in scope of
Running the cursorInfo command in the shell, I only see one cursor for each run of the program. Only when I Ctrl-C does it leak a cursor. If this issue is still of interest to you, would you mind trying out the snapshot build. |