cursorTimeoutMillis parameter does not work. It never expires

I’m testing this parameter and I really want to know how cursorTimeoutMillis parameter works.

I expected that if I set this parameter to 10 seconds,
the cursor would time out in 10 seconds when it is in idle state, but nothing happened. The following is my scenario.

before testing, I prepared my test data like this

for (var i = 1; i <= 101; i++) {
    db.testCollection.insert( { x : i } )
 }

var documentSize = 16 * 1024 * 1024-32; // 16MB
var largeData = new Array(documentSize).join('y');
db.testCollection.insert({ data: largeData });

after creating data, I made my cursor .


> db.adminCommand({"getParameter":1,"cursorTimeoutMillis":1})
{ "cursorTimeoutMillis" : NumberLong(10000), "ok" : 1 }

var myCursor = db.testCollection.find();
var count = 0;

while (myCursor.hasNext()) {
   var document = myCursor.next();
   count++;
   if (count > 101) {
    sleep(60000);         ------> At this point, I expected this cursor should be expired.
    printjson(count)
    var a = document;
   }
   else {
    printjson(count,document)
   }
}

however, this cursor never expired. it ends normally without a cursor timeout.
I don’t understand. What’s the problem?

1 Like

After sleep try myCursor.isExhausted().

Thank you for the response, but it’s not resolved yet.

session 1

kimdubi_repl [direct: primary] test> while (myCursor.hasNext()) {
...   sleep(60000);
...   print(myCursor.isExhausted())
...   var document = myCursor.next();
...   count++;
...   printjson(count)
...   var a = document;
... }




false
1
false
2
false
3

session2

kimdubi_repl [direct: primary] admin> db.aggregate([ { $currentOp: { idleCursors: true } }, { $match: { "ns": "test.testCollection" } }, { $sort: { "cursor.createdDate": 1 } }])
[
  {
    type: 'idleCursor',
    host: '83992e27a784:27017',
    ns: 'test.testCollection',
    lsid: {
      id: new UUID("9944244f-3870-4a3e-8694-7a324ef6228d"),
      uid: Binary(Buffer.from("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "hex"), 0)
    },
    planSummary: 'COLLSCAN',
    cursor: {
      cursorId: Long("3063305060822111253"),
      createdDate: ISODate("2023-08-06T03:51:58.999Z"),
      lastAccessDate: ISODate("2023-08-06T03:54:59.213Z"),
      nDocsReturned: Long("4"),
      nBatchesReturned: Long("4"),
      noCursorTimeout: false,
      tailable: false,
      awaitData: false,
      originatingCommand: {
        find: 'testCollection',
        filter: {},
        lsid: { id: new UUID("9944244f-3870-4a3e-8694-7a324ef6228d") },
        '$clusterTime': {
          clusterTime: Timestamp({ t: 1691293898, i: 1 }),
          signature: {
            hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
            keyId: Long("0")
          }
        },
        '$db': 'test'
      }
    }
  }
]