Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-664

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • 2.9.0
    • API
    • None

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: