[JAVA-664] Use of DBCursor#iterator method can cause a leak of server-side cursor Created: 11/Oct/12  Updated: 26/Nov/13  Resolved: 26/Nov/13

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.9.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Unassigned
Resolution: Won't Fix Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

DBCursor#iterator is implemented to return a copy of "this":

    public Iterator<DBObject> iterator(){
        return this.copy();
    }

So if you have code like:

        DBCursor cursor = c.find();
        try {
            for (DBObject obj: cursor) {
                if (someCondition(obj)) {
                    return obj;
                }
            }
        } finally {
            cursor.close();
        }

The server-side cursor will not be killed, because the DBCursor that is being closed in the finally block is not the DBCursor that has the the cursor id.



 Comments   
Comment by Jeffrey Yemin [ 26/Nov/13 ]

This will be fixed by design with a new cursor API, but this is a design error in the current API and is not really possible to fix properly without breaking compatibility.

Generated at Thu Feb 08 08:52:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.