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

Cursor is not closed after limit is fully fetched from server

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: 2.5
    • Component/s: API
    • Labels:
      None
    • # Replies:
      4
    • Last comment by Customer:
      true

      Description

      We're trying to load all docs from a collection in batches of 100 (to avoid locking the DB for a long period of time). Our objects are large and this eventually causes the MongoDB server to run out of memory.

      I've run a test locally to recreate the problem and it seems that cursors on the server are not being closed. When running the code below the number of open cursors on the server gradually increases.

      int batchSize = 100;
      int i = 0;
      while(true)

      { Iterable<DBObject> cursor = collection.find(new BasicDBObject(ID, new BasicDBObject(GREATER_THAN, i))).sort(new BasicDBObject(ID, 1)).limit(batchSize); List<DBObject> dbos = ImmutableList.copyOf(cursor); i += batchSize; Thread.sleep(1000); }

      The output of db.serverStatus() after about 1 min:

      "cursros" :

      { "totalOpen" : 51, "clientCursors_size" : 51, "timedOut" : 0 }

      ,
      }

      It appears that using a negative limit fixes this, but there appears to be a 4MB upper limit of the number of docs returned. Why does the server keep the cursor open when all the results have been read?

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                7 years, 37 weeks, 4 days ago
                Date of 1st Reply: