Use of DBCursor#iterator method can cause a leak of server-side cursor

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.9.0
    • Component/s: API
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            Unassigned
            Reporter:
            Jeffrey Yemin
            None
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: