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

Cursor is not closed after limit is fully fetched from server

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5
    • Affects Version/s: 2.4
    • Component/s: API
    • None

      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?

            Assignee:
            antoine Antoine Girbal
            Reporter:
            johna John Ayres
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: