Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-35484

Active cursor with Session disappears after a few minutes

    • Type: Icon: Question Question
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.0.0-rc3
    • Component/s: Sharding
    • None

      Hi all,

      I have been investigating NODE-1482, and I have found that, when using sessions, a cursor will disappear after a few minutes and cause further getMores to error.

      Reproduction steps:

      1. Set up a ReplicaSet
      2. Insert 10000 records into test.test
      3. Run the following Node Script Using NodeJS >= 8:

      'use strict';
      
      const {MongoClient} = require('mongodb');
      
      const sleep = ms => new Promise(r => setTimeout(r, ms));
      
      (async () => {
        const client = await MongoClient.connect('mongodb://localhost:27017/?replSet=rs', { monitorCommands: true });
        client.on('commandStarted', e => console.log(JSON.stringify(e.command)));
      
        const collection = client.db('test').collection('test');
      
        const count = await collection.count();
      
        console.log(count);
      
        console.log('querying');
        const time = process.hrtime()
        const cursor = collection.find({}).batchSize(1);
        try {
          for (let i = 0; i < 100000; i++) {
            await cursor.next();
            await sleep(1000);
          }
      
        } catch (e) {
          console.error(e);
        }
      
        console.log('shutting down');
        console.log(process.hrtime(time));
        await cursor.close();
        await client.close();
        console.log('done');
        process.exit(0);
      })();
      

      I'm finding that after about 2 minutes, the getMore will error with cursor X not found. As far as I can tell, we are not sending a killCursor or an endSession command.

      Since users are reporting that this only started happening once we started adding lsid to our find and getMore commands, I suspect this has something to do with sessions.

      Is this a bug, or expected behavior?

      Thanks,
      Dan

            Assignee:
            misha.tyulenev@mongodb.com Misha Tyulenev (Inactive)
            Reporter:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: